BAEL-3926 - Java Map with case-insensitive keys
This commit is contained in:
parent
4a83c73835
commit
40f2f2ea8a
|
@ -26,10 +26,17 @@
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-core</artifactId>
|
||||||
|
<version>${spring.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
|
<spring.version>5.2.5.RELEASE</spring.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.baeldung.map;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.map.CaseInsensitiveMap;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
public class CaseInsensitiveMapUnitTest {
|
||||||
|
@Test
|
||||||
|
public void givenCaseInsensitiveTreeMap_whenTwoEntriesAdded_thenSizeIsOne(){
|
||||||
|
TreeMap<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
|
||||||
|
treeMap.put("abc", 1);
|
||||||
|
treeMap.put("ABC", 2);
|
||||||
|
|
||||||
|
assertEquals(treeMap.size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenCommonsCaseInsensitiveMap_whenSameEntryAdded_thenValueUpdated(){
|
||||||
|
CaseInsensitiveMap<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
|
||||||
|
commonsHashMap.put("abc", 1);
|
||||||
|
commonsHashMap.put("ABC", 2);
|
||||||
|
|
||||||
|
assertEquals(commonsHashMap.get("aBc"), (Integer)2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLinkedCaseInsensitiveMap_whenEntryRemoved_thenSizeIsZero(){
|
||||||
|
LinkedCaseInsensitiveMap<Integer> linkedHashMap = new LinkedCaseInsensitiveMap<>();
|
||||||
|
linkedHashMap.put("abc", 3);
|
||||||
|
linkedHashMap.remove("aBC");
|
||||||
|
|
||||||
|
assertEquals(linkedHashMap.size(), 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue