예제 #1
0
 @Test
 public void toString_A$() throws Exception {
   Either<String, Integer> target = Left.apply("foo");
   String actual = target.toString();
   String expected = "Left(foo)";
   assertThat(actual, is(equalTo(expected)));
 }
예제 #2
0
 @Test
 public void right_A$() throws Exception {
   Either<String, Integer> target = Left.apply("foo");
   Option<Integer> actual = target.right();
   assertThat(actual.isDefined(), is(false));
   assertThat(actual.getOrNull(), is(nullValue()));
 }
예제 #3
0
 @Test
 public void left_A$() throws Exception {
   Either<String, Integer> target = Left.apply("foo");
   Option<String> actual = target.left();
   assertThat(actual.isDefined(), is(true));
   assertThat(actual.getOrNull(), is(equalTo("foo")));
 }
예제 #4
0
 @Test
 public void isRight_A$() throws Exception {
   Either<String, Integer> target = Left.apply("foo");
   boolean actual = target.isRight();
   boolean expected = false;
   assertThat(actual, is(equalTo(expected)));
 }
예제 #5
0
 @Test
 public void swap_A$() throws Exception {
   Either<String, Integer> target = Left.apply("foo");
   Either<Integer, String> swapped = target.swap();
   Option<String> right = swapped.right();
   assertThat(right.isDefined(), is(true));
   assertThat(right.getOrNull(), is(equalTo("foo")));
 }
예제 #6
0
 @Test
 public void mergeToLeft_A$Function1() throws Exception {
   String value = "xxx";
   Either<String, Integer> target = Left.apply(value);
   Function1<Integer, String> rightToLeft =
       new F1<Integer, String>() {
         public String apply(Integer v) {
           return v.toString();
         }
       };
   String actual = target.mergeToLeft(rightToLeft);
   String expected = "xxx";
   assertThat(actual, is(equalTo(expected)));
 }
예제 #7
0
 @Test
 public void mergeToRight_A$Function1() throws Exception {
   String value = "xxx";
   Either<String, Integer> target = Left.apply(value);
   Function1<String, Integer> leftToRight =
       new F1<String, Integer>() {
         public Integer apply(String v) throws Exception {
           return v.length();
         }
       };
   Integer actual = target.mergeToRight(leftToRight);
   Integer expected = 3;
   assertThat(actual, is(equalTo(expected)));
 }