Ejemplo n.º 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()));
 }
Ejemplo n.º 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")));
 }
Ejemplo n.º 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")));
 }
Ejemplo n.º 4
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")));
 }
Ejemplo n.º 5
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)));
 }
Ejemplo n.º 6
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());
  }