Skip to content

Commit

Permalink
Simplify two tests with the new PairMatcher. #42 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Keszthelyi authored and dmfs committed Oct 12, 2017
1 parent bdbd1cb commit d2aba88
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 37 deletions.
1 change: 1 addition & 0 deletions essentials/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ configurations {
apply from: '../publish.gradle'

dependencies {
testCompile project(':jems-testing')
testCompile 'junit:junit:' + JUNIT
testCompile 'org.hamcrest:hamcrest-all:' + HAMCREST
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.junit.Test;

import static org.dmfs.jems.pair.hamcrest.PairMatcher.pair;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;

Expand All @@ -34,27 +35,12 @@ public final class PairingFunctionTest
@Test
public void test()
{
LeftHand leftHand = new LeftHand();
RightHand rightHand = new RightHand();
String left = new String("a");
Integer right = new Integer(1);

PairingFunction<LeftHand, RightHand> pairingFunction = new PairingFunction<>();
assertThat(pairingFunction.value(leftHand, rightHand).left(), sameInstance(leftHand));
assertThat(pairingFunction.value(leftHand, rightHand).right(), sameInstance(rightHand));

assertThat(PairingFunction.<LeftHand, RightHand>instance().value(leftHand, rightHand).left(), sameInstance(leftHand));
assertThat(PairingFunction.<LeftHand, RightHand>instance().value(leftHand, rightHand).right(), sameInstance(rightHand));
}


private static final class LeftHand
{

}


private static final class RightHand
{
assertThat(new PairingFunction<String, Integer>().value(left, right), pair(sameInstance(left), sameInstance(right)));

assertThat(PairingFunction.<String, Integer>instance().value(left, right), pair(sameInstance(left), sameInstance(right)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.junit.Test;

import static org.dmfs.jems.pair.hamcrest.PairMatcher.pair;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;

Expand All @@ -33,25 +34,10 @@ public final class ValuePairTest
@Test
public void testThatSameInstancesAreReturned()
{
LeftHand leftHand = new LeftHand();
RightHand rightHand = new RightHand();

ValuePair<LeftHand, RightHand> hands = new ValuePair<>(leftHand, rightHand);

assertThat(hands.left(), sameInstance(leftHand));
assertThat(hands.right(), sameInstance(rightHand));
}


private final static class LeftHand
{

}


private final static class RightHand
{
String left = new String("a");
Integer right = new Integer(1);

assertThat(new ValuePair<>(left, right), pair(sameInstance(left), sameInstance(right)));
}

}

0 comments on commit d2aba88

Please sign in to comment.