Skip to content

Instantly share code, notes, and snippets.

@darsen
darsen / AddtionTest.java
Last active December 14, 2015 14:58
Parameterized tests in JUnit Parameterized tests in JUnit can be very useful when writing tests based on tabular data. These type of tests can save you from writing a lot of duplicate or boilerplate code. While there is a fair amount of articles on the subject on the Internet, I wasn’t able to find a code sample that you can simply copy into you…
package com.empoweragile;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@darsen
darsen / Money.js
Last active December 17, 2015 02:18
Using Jasmine and custom matchers to check object equality.
function Money(amount, currency){
this.amount = amount;
this.currency = currency;
this.sum = function (money){
return new Money(200, "CLP");
}
}
@darsen
darsen / SimpleJava8Lambda.java
Last active December 16, 2017 12:50
Java Simple Lambda Koan
interface Caps {
public String capitalize(String name);
}
@Koan
public void simpleLambda() {
Caps caps = (String n) -> {
return n.toUpperCase();
};
String capitalized = caps.capitalize("James");
@darsen
darsen / SampleJavKoan.java
Created July 13, 2015 19:27
Sample Java Code Koan
@Koan
public void localTime () {
LocalTime t1 = LocalTime.of(7,30);
assertEquals(t1, LocalTime.parse(__));
}
@darsen
darsen / CustomTextField.swift
Created August 6, 2015 16:07
Custom TextField in swift
import Foundation
import UIKit
class CustomTextField: UITextField, UITextFieldDelegate{
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.delegate = self
}
import XCTest
class AsyncTests: XCTestCase {
func testExample() {
//set expectaton
let expectation = expectationWithDescription("Swift Expectations")
let url = NSURL(string: "http://www.stackoverflow.com")
let request = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
@darsen
darsen / TestController.cs
Created March 25, 2016 16:17
Send complex objects to .Net Web Api through URL using FromUri attribute
namespace FromUri.Controllers
{
using System;
using System.Web.Http;
/// <summary>
/// Url sample call:
/// http://localhost:50872/api/test?key.org=abc&key.dest=123&key.when=2010-01-01T00:00:00&foo=1&bar=bbbrr&foobar.foo=2&foobar.bar=xyz
/// </summary>
using Simple.HttpClientFactory;
using Simple.HttpClientFactory.MessageHandlers;
using System;
using System.Net.Http;
namespace HttpClientFactory472
{
internal class Program
{
//use static handler to reuse ports