Add test for normal Mon.factory() behaviour

This commit is contained in:
Paul Campbell 2017-12-31 19:21:58 +00:00
parent 0f93915297
commit 80023809a4

View file

@ -113,6 +113,20 @@ public class MonTest {
.withMessage("onInvalid"); .withMessage("onInvalid");
} }
@Test
public void factory() {
//given
final Function<Integer, Optional<?>> evenMonFactory =
Mon.factory((Integer v) -> v % 2 == 0, Optional::of, Optional::empty);
//when
final Optional<?> oddResult = evenMonFactory.apply(1);
final Optional<?> evenResult = evenMonFactory.apply(2);
//then
assertThat(oddResult).isEmpty();// because 1 % 2 != 0
assertThat(evenResult).isNotEmpty(); // because 2 % 2 == 0
evenResult.ifPresent(value -> assertThat(value).isEqualTo(Mon.of(2)));
}
@Test @Test
public void shouldGetInvalidResultWhenFactoryApplyWithNull() { public void shouldGetInvalidResultWhenFactoryApplyWithNull() {
//given //given