BAEL-586 increment guava version, move Test to guava module
This commit is contained in:
parent
91fb87c06d
commit
30d9102310
|
@ -92,7 +92,7 @@
|
|||
|
||||
<properties>
|
||||
<!-- util -->
|
||||
<guava.version>19.0</guava.version>
|
||||
<guava.version>21.0</guava.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
|
||||
|
|
|
@ -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<String, String> 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<String, String> 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<String, List<String>> map = new LinkedHashMap<>();
|
||||
|
||||
//when
|
||||
List<String> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<String, String> 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<String, String> 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<String, List<String>> map = new LinkedHashMap<>();
|
||||
|
||||
//when
|
||||
List<String> 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue