Example #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()));
 }
Example #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")));
 }
Example #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")));
 }
Example #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));
 }
Example #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));
 }
Example #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")));
 }
Example #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)));
 }
Example #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());
  }
Example #9
0
 @Test
 public void __A$Option() throws Exception {
   Either<String, Integer> target = Left.apply(Option.apply("foo"));
   assertThat(target, notNullValue());
 }