ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/collections/TestCaseInsensitiveKeyMap.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/collections/TestCaseInsensitiveKeyMap.java
Status
scanned
Type
file
Name
TestCaseInsensitiveKeyMap.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
5910 (5.8 KB)
MD5
87f5d6464518e6772956212513170cf8
SHA1
6ed875a69be7c55d859d0c4da3c8c0ef135ba7ab
SHA256
3bc8d47cbd59bfb7b5f75c57497625c51e985c08541d7018caaba1105ff505a2
SHA512

      
    
SHA1_git
b3edbe36ec18c6b3ec7fd907c22e68f16640f7d7
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestCaseInsensitiveKeyMap.java | 5.8 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.tomcat.util.collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.junit.Assert; import org.junit.Test; public class TestCaseInsensitiveKeyMap { @Test public void testPut() { Object o1 = new Object(); Object o2 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Object o = map.put("A", o2); Assert.assertEquals(o1, o); Assert.assertEquals(o2, map.get("a")); Assert.assertEquals(o2, map.get("A")); } @Test(expected=NullPointerException.class) public void testPutNullKey() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put(null, o1); } @Test public void testGet() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertEquals(o1, map.get("a")); Assert.assertEquals(o1, map.get("A")); } @Test public void testGetNullKey() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertNull(map.get(null)); } @Test public void testContainsKey() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertTrue(map.containsKey("a")); Assert.assertTrue(map.containsKey("A")); } @Test public void testContainsKeyNonString() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertFalse(map.containsKey(o1)); } @Test public void testContainsKeyNull() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertFalse(map.containsKey(null)); } @Test public void testContainsValue() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertTrue(map.containsValue(o1)); } @Test public void testRemove() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Assert.assertFalse(map.isEmpty()); map.remove("A"); Assert.assertTrue(map.isEmpty()); map.put("A", o1); Assert.assertFalse(map.isEmpty()); map.remove("a"); Assert.assertTrue(map.isEmpty()); } @Test public void testClear() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); for (int i = 0; i < 10; i++) { map.put(Integer.toString(i), o1); } Assert.assertEquals(10, map.size()); map.clear(); Assert.assertEquals(0, map.size()); } @Test public void testPutAll() { Object o1 = new Object(); Object o2 = new Object(); Map<String,Object> source = new HashMap<>(); source.put("a", o1); source.put("A", o2); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.putAll(source); Assert.assertEquals(1, map.size()); Assert.assertTrue(map.containsValue(o1) != map.containsValue(o2)); } @Test public void testKeySetContains() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Set<String> keys = map.keySet(); Assert.assertTrue(keys.contains("a")); Assert.assertTrue(keys.contains("A")); } @Test public void testKeySetRemove() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Iterator<String> iter = map.keySet().iterator(); Assert.assertTrue(iter.hasNext()); iter.next(); iter.remove(); Assert.assertTrue(map.isEmpty()); } @Test public void testEntrySetRemove() { Object o1 = new Object(); CaseInsensitiveKeyMap<Object> map = new CaseInsensitiveKeyMap<>(); map.put("a", o1); Iterator<Entry<String,Object>> iter = map.entrySet().iterator(); Assert.assertTrue(iter.hasNext()); Entry<String,Object> entry = iter.next(); Assert.assertEquals("a", entry.getKey()); Assert.assertEquals(o1, entry.getValue()); iter.remove(); Assert.assertTrue(map.isEmpty()); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
20.45
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9