Skip to content

Commit

Permalink
updating Java9ObjectsAPIUnitTest (eugenp#2430)
Browse files Browse the repository at this point in the history
* updating Java9ObjectsAPIUnitTest

* some more changes to test
  • Loading branch information
sanaulla123 authored and maibin committed Aug 13, 2017
1 parent e13204c commit 299432d
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,27 @@
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)
Expand All @@ -30,8 +40,8 @@ public void givenNull_whenRequireNonNullElse_thenException(){

@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
Expand Down

0 comments on commit 299432d

Please sign in to comment.