BAEL-586 proper file for test

This commit is contained in:
Tomasz Lelek 2017-01-14 10:11:52 +01:00
parent 30d9102310
commit 75bc156357
2 changed files with 63 additions and 49 deletions

View File

@ -0,0 +1,63 @@
package org.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 GuavaMultiMapTest {
@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());
}
}

View File

@ -211,53 +211,4 @@ 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());
}
}
}