updating Java9ObjectsAPIUnitTest (#2430)

* updating Java9ObjectsAPIUnitTest

* some more changes to test
This commit is contained in:
Mohamed Sanaulla 2017-08-13 21:06:42 +03:00 committed by maibin
parent e13204ca96
commit 299432df11
1 changed files with 17 additions and 7 deletions

View File

@ -10,17 +10,27 @@ import static org.hamcrest.Matchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
public class Java9ObjectsAPIUnitTest {
private List<String> aMethodReturningNullList(){
return null;
}
@Test
public void givenNullObject_whenRequireNonNullElse_thenElse(){
assertThat(Objects.<List>requireNonNullElse(null, Collections.EMPTY_LIST),
is(Collections.EMPTY_LIST));
List<String> aList = Objects.<List>requireNonNullElse(
aMethodReturningNullList(), Collections.EMPTY_LIST);
assertThat(aList, is(Collections.EMPTY_LIST));
}
private List<String> aMethodReturningNonNullList(){
return List.of("item1", "item2");
}
@Test
public void givenObject_whenRequireNonNullElse_thenObject(){
assertThat(Objects.<List>requireNonNullElse(List.of("item1", "item2"),
Collections.EMPTY_LIST), is(List.of("item1", "item2")));
List<String> aList = Objects.<List>requireNonNullElse(
aMethodReturningNonNullList(), Collections.EMPTY_LIST);
assertThat(aList, is(List.of("item1", "item2")));
}
@Test(expected = NullPointerException.class)
@ -30,8 +40,8 @@ public class Java9ObjectsAPIUnitTest {
@Test
public void givenObject_whenRequireNonNullElseGet_thenObject(){
assertThat(Objects.<List>requireNonNullElseGet(null, List::of),
is(List.of()));
List<String> aList = Objects.<List>requireNonNullElseGet(null, List::of);
assertThat(aList, is(List.of()));
}
@Test