From 30d9102310434913de614e0b3c61aa93751694a8 Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Sat, 14 Jan 2017 10:07:53 +0100 Subject: [PATCH] BAEL-586 increment guava version, move Test to guava module --- guava/pom.xml | 2 +- .../org/baeldung/guava/GuavaStringTest.java | 57 +++++++++++++++-- .../java/com/baeldung/guava/MultimapTest.java | 62 ------------------- 3 files changed, 52 insertions(+), 69 deletions(-) delete mode 100644 guava19/src/test/java/com/baeldung/guava/MultimapTest.java diff --git a/guava/pom.xml b/guava/pom.xml index a7b4e79e34..0a50fad2c3 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -92,7 +92,7 @@ - 19.0 + 21.0 3.5 4.1 diff --git a/guava/src/test/java/org/baeldung/guava/GuavaStringTest.java b/guava/src/test/java/org/baeldung/guava/GuavaStringTest.java index be230a9b0e..7cf986baaf 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaStringTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaStringTest.java @@ -8,10 +8,9 @@ import static org.junit.Assert.assertTrue; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; +import com.google.common.collect.*; import org.junit.Test; import com.google.common.base.CharMatcher; @@ -19,9 +18,6 @@ import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Predicate; import com.google.common.base.Splitter; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; public class GuavaStringTest { @@ -215,4 +211,53 @@ public class GuavaStringTest { assertEquals("hello", result); } + public static class MultimapTest { + + @Test + public void givenMap_whenAddTwoValuesForSameKey_shouldOverridePreviousKey() { + //given + String key = "a-key"; + Map map = new LinkedHashMap<>(); + + //when + map.put(key, "firstValue"); + map.put(key, "secondValue"); + + //then + assertEquals(1, map.size()); + } + + @Test + public void givenMultiMap_whenAddTwoValuesForSameKey_shouldHaveTwoEntriesInMap() { + //given + String key = "a-key"; + Multimap map = ArrayListMultimap.create(); + + //when + map.put(key, "firstValue"); + map.put(key, "secondValue"); + + //then + assertEquals(2, map.size()); + } + + @Test + public void givenMapOfListValues_whenAddTwoValuesForSameKey_shouldHaveTwoElementsInList() { + //given + String key = "a-key"; + Map> map = new LinkedHashMap<>(); + + //when + List values = map.get(key); + if(values == null){ + values = new LinkedList<>(); + values.add("firstValue"); + values.add("secondValue"); + } + map.put(key, values); + + //then + assertEquals(1, map.size()); + } + } } diff --git a/guava19/src/test/java/com/baeldung/guava/MultimapTest.java b/guava19/src/test/java/com/baeldung/guava/MultimapTest.java deleted file mode 100644 index c984ab1e4b..0000000000 --- a/guava19/src/test/java/com/baeldung/guava/MultimapTest.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.baeldung.guava; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import org.junit.Test; - -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.assertEquals; - -public class MultimapTest { - - @Test - public void givenMap_whenAddTwoValuesForSameKey_shouldOverridePreviousKey() { - //given - String key = "a-key"; - Map map = new LinkedHashMap<>(); - - //when - map.put(key, "firstValue"); - map.put(key, "secondValue"); - - //then - assertEquals(1, map.size()); - } - - @Test - public void givenMultiMap_whenAddTwoValuesForSameKey_shouldHaveTwoEntriesInMap() { - //given - String key = "a-key"; - Multimap map = ArrayListMultimap.create(); - - //when - map.put(key, "firstValue"); - map.put(key, "secondValue"); - - //then - assertEquals(2, map.size()); - } - - @Test - public void givenMapOfListValues_whenAddTwoValuesForSameKey_shouldHaveTwoElementsInList() { - //given - String key = "a-key"; - Map> map = new LinkedHashMap<>(); - - //when - List values = map.get(key); - if(values == null){ - values = new LinkedList<>(); - values.add("firstValue"); - values.add("secondValue"); - } - map.put(key, values); - - //then - assertEquals(1, map.size()); - } -}