From 80023809a4597185eed6970058aae1076b4115ff Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 31 Dec 2017 19:21:58 +0000 Subject: [PATCH] Add test for normal Mon.factory() behaviour --- src/test/java/net/kemitix/mon/MonTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/net/kemitix/mon/MonTest.java b/src/test/java/net/kemitix/mon/MonTest.java index 3d8a660..7e5f8e2 100644 --- a/src/test/java/net/kemitix/mon/MonTest.java +++ b/src/test/java/net/kemitix/mon/MonTest.java @@ -113,6 +113,20 @@ public class MonTest { .withMessage("onInvalid"); } + @Test + public void factory() { + //given + final Function> 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 public void shouldGetInvalidResultWhenFactoryApplyWithNull() { //given