@Test public void testAlreadyWritableMap() { final HashedMap<String, String> hashedMap = new HashedMap<String, String>(); assertSame(hashedMap, SplitMapUtils.writableMap(hashedMap)); }
@Test @SuppressWarnings("unchecked") public void testWritableMap() { final Map<String, String> map = SplitMapUtils.writableMap(transformedMap); attemptGetOperation( new Runnable() { public void run() { map.get(null); } }); attemptGetOperation( new Runnable() { public void run() { map.entrySet(); } }); attemptGetOperation( new Runnable() { public void run() { map.keySet(); } }); attemptGetOperation( new Runnable() { public void run() { map.values(); } }); attemptGetOperation( new Runnable() { public void run() { map.size(); } }); attemptGetOperation( new Runnable() { public void run() { map.isEmpty(); } }); attemptGetOperation( new Runnable() { public void run() { map.containsKey(null); } }); attemptGetOperation( new Runnable() { public void run() { map.containsValue(null); } }); attemptGetOperation( new Runnable() { public void run() { map.remove(null); } }); // equals, hashcode final Map<String, String> other = SplitMapUtils.writableMap(transformedMap); assertEquals(other, map); assertEquals(other.hashCode(), map.hashCode()); // put int sz = backingMap.size(); assertFalse(backingMap.containsKey("foo")); map.put("new", "66"); assertEquals(++sz, backingMap.size()); // putall final Map<String, String> more = new HashMap<String, String>(); more.put("foo", "77"); more.put("bar", "88"); more.put("baz", "99"); map.putAll(more); assertEquals(sz + more.size(), backingMap.size()); // clear map.clear(); assertTrue(backingMap.isEmpty()); assertSame(map, SplitMapUtils.writableMap((Put<String, String>) map)); }