예제 #1
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()));
 }
예제 #2
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")));
 }
예제 #3
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")));
 }
예제 #4
0
 @Test
 public void flatMap_A$Function1() throws Exception {
   String value = "vvv";
   Some<String> target = new Some<String>(value);
   F1<String, Option<String>> f =
       new F1<String, Option<String>>() {
         @Override
         public Option<String> apply(String v1) {
           return Option.apply(v1);
         }
       };
   Option<String> actual = target.flatMap(f);
   assertThat(actual.isDefined(), is(true));
 }
예제 #5
0
 @Test
 public void filter_A$Function1() throws Exception {
   String value = "vvv";
   Some<String> target = new Some<String>(value);
   F1<String, Boolean> f =
       new F1<String, Boolean>() {
         @Override
         public Boolean apply(String v1) {
           return true;
         }
       };
   Option<String> actual = target.filter(f);
   assertThat(actual.isDefined(), is(true));
 }
예제 #6
0
 @Test
 public void map_A$Function1() throws Exception {
   String value = "vvv";
   Some<String> target = new Some<String>(value);
   F1<String, String> f =
       new F1<String, String>() {
         @Override
         public String apply(String v1) {
           return v1;
         }
       };
   Option<String> actual = target.map(f);
   assertThat(actual.getOrNull(), is(equalTo("vvv")));
 }
예제 #7
0
 @Test
 public void flatMap_A$F1() throws Exception {
   String value = "vvv";
   Some<String> target = new Some<String>(value);
   F1<String, Option<Integer>> f =
       new F1<String, Option<Integer>>() {
         @Override
         public Option<Integer> apply(String v1) {
           return Option.apply(v1.length());
         }
       };
   Option<Integer> actual = target.flatMap(f);
   assertThat(actual.getOrNull(), is(equalTo(3)));
 }
예제 #8
0
  @Test
  public void filter_A$F1() throws Exception {
    String value = "vvv";
    Some<String> target = new Some<String>(value);
    F1<String, Boolean> isStartsWithv =
        new F1<String, Boolean>() {
          @Override
          public Boolean apply(String v1) {
            return v1.startsWith("v");
          }
        };
    F1<String, Boolean> isStartsWithw =
        new F1<String, Boolean>() {
          @Override
          public Boolean apply(String v1) {
            return v1.startsWith("w");
          }
        };
    Option<String> actual = target.filter(isStartsWithv);
    assertThat(actual.getOrNull(), is(equalTo("vvv")));

    Option<String> actual2 = target.filter(isStartsWithw);
    assertNull(actual2.getOrNull());
  }
예제 #9
0
 @Test
 public void __A$Option() throws Exception {
   Either<String, Integer> target = Left.apply(Option.apply("foo"));
   assertThat(target, notNullValue());
 }