Add test for normal Mon.factory() behaviour
This commit is contained in:
parent
0f93915297
commit
80023809a4
1 changed files with 14 additions and 0 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue