From 591900f3927338c8217d556b44afafeac89729da Mon Sep 17 00:00:00 2001 From: DOHA Date: Thu, 30 Oct 2014 17:12:46 +0200 Subject: [PATCH] Modify class GuavaCollectionTypesTest --- .../guava/GuavaCollectionTypesTest.java | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java b/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java index 31ed0d0661..afb31e56a5 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaCollectionTypesTest.java @@ -44,13 +44,22 @@ import com.google.common.collect.TreeRangeSet; public class GuavaCollectionTypesTest { @Test - public void whenReverseList_thenReversed() { + public void whenCreateList_thenCreated() { final List names = Lists.newArrayList("John", "Adam", "Jane"); + names.add("Tom"); assertEquals(4, names.size()); + names.remove("Adam"); + assertThat(names, contains("John", "Jane", "Tom")); + } + + @Test + public void whenReverseList_thenReversed() { + final List names = Lists.newArrayList("John", "Adam", "Jane"); + final List reversed = Lists.reverse(names); - assertThat(reversed, contains("Tom", "Jane", "Adam", "John")); + assertThat(reversed, contains("Jane", "Adam", "John")); } @Test @@ -61,6 +70,26 @@ public class GuavaCollectionTypesTest { assertThat(chars, contains('J', 'o', 'h', 'n')); } + @Test + public void whenPartitionList_thenPartitioned() { + final List names = Lists.newArrayList("John", "Jane", "Adam", "Tom", "Viki", "Tyler"); + final List> result = Lists.partition(names, 2); + + assertEquals(3, result.size()); + assertThat(result.get(0), contains("John", "Jane")); + assertThat(result.get(1), contains("Adam", "Tom")); + assertThat(result.get(2), contains("Viki", "Tyler")); + } + + @Test + public void whenRemoveDuplicatesFromList_thenRemoved() { + final List chars = Lists.newArrayList('h', 'e', 'l', 'l', 'o'); + assertEquals(5, chars.size()); + + final List result = ImmutableSet.copyOf(chars).asList(); + assertThat(result, contains('h', 'e', 'l', 'o')); + } + @Test public void whenCalculateUnion_thenCorrect() { final Set first = ImmutableSet.of('a', 'b', 'c'); @@ -143,7 +172,7 @@ public class GuavaCollectionTypesTest { } @Test - public void whenCreateMap_thenCreated() { + public void whenCreateImmutableMap_thenCreated() { final Map salary = ImmutableMap. builder().put("John", 1000).put("Jane", 1500).put("Adam", 2000).put("Tom", 2000).build(); assertEquals(1000, salary.get("John").intValue());