From 037f27809e2a05eedabf47ec30f49e2249c78f81 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 2 Nov 2014 02:37:48 +0200 Subject: [PATCH] Modify class GuavaCollectionTypesTest --- .../guava/GuavaCollectionTypesTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java b/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java index dc6f8afb71..029179df91 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java @@ -14,6 +14,7 @@ import org.junit.Test; import com.google.common.base.Function; import com.google.common.base.Joiner; +import com.google.common.base.Predicates; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.BiMap; import com.google.common.collect.ClassToInstanceMap; @@ -90,6 +91,26 @@ public class GuavaCollectionTypesTest { assertThat(result, contains('h', 'e', 'l', 'o')); } + @Test + public void whenRemoveNullFromList_thenRemoved() { + final List names = Lists.newArrayList("John", null, "Adam", null, "Jane"); + Iterables.removeIf(names, Predicates.isNull()); + + assertEquals(3, names.size()); + assertThat(names, contains("John", "Adam", "Jane")); + } + + @Test + public void whenCreateImmutableList_thenCreated() { + final List names = Lists.newArrayList("John", "Adam", "Jane"); + + names.add("Tom"); + assertEquals(4, names.size()); + + final ImmutableList immutable = ImmutableList.copyOf(names); + assertThat(immutable, contains("John", "Adam", "Jane", "Tom")); + } + @Test public void whenCalculateUnion_thenCorrect() { final Set first = ImmutableSet.of('a', 'b', 'c');