new module has been added

This commit is contained in:
omerfinger 2020-03-28 17:50:20 +03:00
parent 0b2e7e9f7c
commit b2bc2dc004
4 changed files with 11 additions and 111 deletions

View File

@ -26,17 +26,10 @@
<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>

View File

@ -1,94 +1,38 @@
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 java.util.Map;
import java.util.TreeMap;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.util.TreeMap;
public class CaseInsensitiveMapUnitTest { public class CaseInsensitiveMapUnitTest {
@Test @Test
public void givenCaseInsensitiveTreeMap_whenTwoEntriesAdded_thenSizeIsOne(){ public void givenCaseInsensitiveTreeMap_whenTwoEntriesAdded_thenSizeIsOne(){
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); TreeMap<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);
assertEquals(1, treeMap.size()); assertEquals(treeMap.size(), 1);
}
@Test
public void givenCommonsCaseInsensitiveMap_whenTwoEntriesAdded_thenSizeIsOne(){
Map<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
commonsHashMap.put("abc", 1);
commonsHashMap.put("ABC", 2);
assertEquals(1, commonsHashMap.size());
}
@Test
public void givenLinkedCaseInsensitiveMap_whenTwoEntriesAdded_thenSizeIsOne(){
Map<String, Integer> linkedHashMap = new LinkedCaseInsensitiveMap<>();
linkedHashMap.put("abc", 1);
linkedHashMap.put("ABC", 2);
assertEquals(1, linkedHashMap.size());
}
@Test
public void givenCaseInsensitiveTreeMap_whenSameEntryAdded_thenValueUpdated(){
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
treeMap.put("abc", 1);
treeMap.put("ABC", 2);
assertEquals(2, treeMap.get("aBc").intValue());
assertEquals(2, treeMap.get("ABc").intValue());
} }
@Test @Test
public void givenCommonsCaseInsensitiveMap_whenSameEntryAdded_thenValueUpdated(){ public void givenCommonsCaseInsensitiveMap_whenSameEntryAdded_thenValueUpdated(){
Map<String, Integer> commonsHashMap = new CaseInsensitiveMap<>(); CaseInsensitiveMap<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
commonsHashMap.put("abc", 1); commonsHashMap.put("abc", 1);
commonsHashMap.put("ABC", 2); commonsHashMap.put("ABC", 2);
assertEquals(2, commonsHashMap.get("aBc").intValue()); Assert.assertEquals(commonsHashMap.get("aBc"), (Integer)2);
assertEquals(2, commonsHashMap.get("ABc").intValue());
}
@Test
public void givenLinkedCaseInsensitiveMap_whenSameEntryAdded_thenValueUpdated(){
Map<String, Integer> linkedHashMap = new LinkedCaseInsensitiveMap<>();
linkedHashMap.put("abc", 1);
linkedHashMap.put("ABC", 2);
assertEquals(2, linkedHashMap.get("aBc").intValue());
assertEquals(2, linkedHashMap.get("ABc").intValue());
}
@Test
public void givenCaseInsensitiveTreeMap_whenEntryRemoved_thenSizeIsZero(){
Map<String, Integer> treeMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
treeMap.put("abc", 3);
treeMap.remove("aBC");
assertEquals(0, treeMap.size());
}
@Test
public void givenCommonsCaseInsensitiveMap_whenEntryRemoved_thenSizeIsZero(){
Map<String, Integer> commonsHashMap = new CaseInsensitiveMap<>();
commonsHashMap.put("abc", 3);
commonsHashMap.remove("aBC");
assertEquals(0, commonsHashMap.size());
} }
@Test @Test
public void givenLinkedCaseInsensitiveMap_whenEntryRemoved_thenSizeIsZero(){ public void givenLinkedCaseInsensitiveMap_whenEntryRemoved_thenSizeIsZero(){
Map<String, Integer> linkedHashMap = new LinkedCaseInsensitiveMap<>(); LinkedCaseInsensitiveMap<Integer> linkedHashMap = new LinkedCaseInsensitiveMap<>();
linkedHashMap.put("abc", 3); linkedHashMap.put("abc", 3);
linkedHashMap.remove("aBC"); linkedHashMap.remove("aBC");
assertEquals(0, linkedHashMap.size()); Assert.assertEquals(linkedHashMap.size(), 0);
} }
} }

View File

@ -1,37 +0,0 @@
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);
}
}