tests has been added and split
This commit is contained in:
parent
da97125e20
commit
ac21dcc346
@ -1,17 +1,16 @@
|
|||||||
package com.baeldung.map.caseinsensitivekeys;
|
package com.baeldung.map.caseinsensitivekeys;
|
||||||
|
|
||||||
import org.apache.commons.collections4.map.CaseInsensitiveMap;
|
import org.apache.commons.collections4.map.CaseInsensitiveMap;
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
import static org.junit.Assert.*;
|
import java.util.Map;
|
||||||
|
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class CaseInsensitiveMapUnitTest {
|
public class CaseInsensitiveMapUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenCaseInsensitiveTreeMap_whenTwoEntriesAdded_thenSizeIsOne(){
|
public void givenCaseInsensitiveTreeMap_whenTwoEntriesAdded_thenSizeIsOne(){
|
||||||
TreeMap<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
treeMap.put("abc", 1);
|
treeMap.put("abc", 1);
|
||||||
treeMap.put("ABC", 2);
|
treeMap.put("ABC", 2);
|
||||||
|
|
||||||
@ -21,7 +20,7 @@ public class CaseInsensitiveMapUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCommonsCaseInsensitiveMap_whenTwoEntriesAdded_thenSizeIsOne(){
|
public void givenCommonsCaseInsensitiveMap_whenTwoEntriesAdded_thenSizeIsOne(){
|
||||||
CaseInsensitiveMap<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
Map<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
||||||
commonsHashMap.put("abc", 1);
|
commonsHashMap.put("abc", 1);
|
||||||
commonsHashMap.put("ABC", 2);
|
commonsHashMap.put("ABC", 2);
|
||||||
|
|
||||||
@ -41,20 +40,20 @@ public class CaseInsensitiveMapUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCaseInsensitiveTreeMap_whenSameEntryAdded_thenValueUpdated(){
|
public void givenCaseInsensitiveTreeMap_whenSameEntryAdded_thenValueUpdated(){
|
||||||
TreeMap<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
treeMap.put("abc", 1);
|
treeMap.put("abc", 1);
|
||||||
treeMap.put("ABC", 2);
|
treeMap.put("ABC", 2);
|
||||||
|
|
||||||
Assert.assertEquals((Integer)2, treeMap.get("aBc"));
|
assertEquals((Integer)2, treeMap.get("aBc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCommonsCaseInsensitiveMap_whenSameEntryAdded_thenValueUpdated(){
|
public void givenCommonsCaseInsensitiveMap_whenSameEntryAdded_thenValueUpdated(){
|
||||||
CaseInsensitiveMap<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
Map<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
||||||
commonsHashMap.put("abc", 1);
|
commonsHashMap.put("abc", 1);
|
||||||
commonsHashMap.put("ABC", 2);
|
commonsHashMap.put("ABC", 2);
|
||||||
|
|
||||||
Assert.assertEquals((Integer)2, commonsHashMap.get("aBc"));
|
assertEquals((Integer)2, commonsHashMap.get("aBc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -63,25 +62,25 @@ public class CaseInsensitiveMapUnitTest {
|
|||||||
linkedHashMap.put("abc", 1);
|
linkedHashMap.put("abc", 1);
|
||||||
linkedHashMap.put("ABC", 2);
|
linkedHashMap.put("ABC", 2);
|
||||||
|
|
||||||
Assert.assertEquals((Integer)2, linkedHashMap.get("aBc"));
|
assertEquals((Integer)2, linkedHashMap.get("aBc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCaseInsensitiveTreeMap_whenEntryRemoved_thenSizeIsZero(){
|
public void givenCaseInsensitiveTreeMap_whenEntryRemoved_thenSizeIsZero(){
|
||||||
TreeMap<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
treeMap.put("abc", 3);
|
treeMap.put("abc", 3);
|
||||||
treeMap.remove("aBC");
|
treeMap.remove("aBC");
|
||||||
|
|
||||||
Assert.assertEquals(0, treeMap.size());
|
assertEquals(0, treeMap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenCommonsCaseInsensitiveMap_whenEntryRemoved_thenSizeIsZero(){
|
public void givenCommonsCaseInsensitiveMap_whenEntryRemoved_thenSizeIsZero(){
|
||||||
CaseInsensitiveMap<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
Map<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
||||||
commonsHashMap.put("abc", 3);
|
commonsHashMap.put("abc", 3);
|
||||||
commonsHashMap.remove("aBC");
|
commonsHashMap.remove("aBC");
|
||||||
|
|
||||||
Assert.assertEquals(0, commonsHashMap.size());
|
assertEquals(0, commonsHashMap.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -90,6 +89,6 @@ public class CaseInsensitiveMapUnitTest {
|
|||||||
linkedHashMap.put("abc", 3);
|
linkedHashMap.put("abc", 3);
|
||||||
linkedHashMap.remove("aBC");
|
linkedHashMap.remove("aBC");
|
||||||
|
|
||||||
Assert.assertEquals(0, linkedHashMap.size());
|
assertEquals(0, linkedHashMap.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user