public void testAsEMap() throws Exception { Map<String, String> map = new HashMap<String, String>(); EMap<String, String> eMap = ECollections.asEMap(map); Map.Entry<String, String> entry = ECollections.singletonEMap("x", "y").get(0); map.put("aKey", "aValue"); assertEquivalent(map, eMap); eMap.put("bKey", "bValue"); assertEquivalent(map, eMap); try { eMap.move(1, 0); fail("move(int, int) should throw UnsupportedOperationException)"); } catch (UnsupportedOperationException exception) { // We expect to get here. } try { eMap.move(1, eMap.get(0)); fail("move(int, Object) should throw UnsupportedOperationException)"); } catch (UnsupportedOperationException exception) { // We expect to get here. } try { eMap.add(0, entry); fail("add(int, Object) should throw UnsupportedOperationException)"); } catch (UnsupportedOperationException exception) { // We expect to get here. } try { eMap.addAll(0, Collections.singleton(entry)); fail("addAll(int, Collection) should throw UnsupportedOperationException)"); } catch (UnsupportedOperationException exception) { // We expect to get here. } eMap.add(entry); assertEquivalent(map, eMap); eMap.remove(entry); assertEquivalent(map, eMap); map.put("aKey", "aValue2"); assertEquivalent(map, eMap); eMap.put("bKey", "bValue2"); assertEquivalent(map, eMap); map.remove("aKey"); assertEquivalent(map, eMap); eMap.remove("bKey"); assertEquivalent(map, eMap); Map<String, String> otherMap = new HashMap<String, String>(); otherMap.put("aKey", "aValue"); otherMap.put("bKey", "bValue"); map.putAll(otherMap); assertEquivalent(map, eMap); map.clear(); assertEquivalent(map, eMap); EMap<String, String> otherEMap = ECollections.asEMap(map); otherEMap.put("aKey", "aValue"); otherEMap.put("bKey", "bValue"); eMap.putAll(otherEMap); assertEquivalent(map, eMap); eMap.clear(); assertEquivalent(map, eMap); }