/** * No matter how many times we wrap instances in instances, the backing map must remain * the same. */ public void testMapWrapping() { ValueProtectingMap<String, Serializable> mapTwo = new ValueProtectingMap<String, Serializable>(map); assertTrue("Backing map must be shared: ", mapTwo.getProtectedMap() == map.getProtectedMap()); ValueProtectingMap<String, Serializable> mapThree = new ValueProtectingMap<String, Serializable>(map); assertTrue("Backing map must be shared: ", mapThree.getProtectedMap() == map.getProtectedMap()); }
/** * Make sure that NOTHING has changed in our 'holy' map */ private void checkMaps(boolean expectMapClone) { assertEquals("Holy map size is wrong: ", 5, holyMap.size()); // Note that the immutability of the maps and lists means that we don't need // to check every value within the lists and maps if (expectMapClone) { // Make sure that the holy map has been released assertTrue("Expect holy map to have been released: ", map.getProtectedMap() != holyMap); // Do some updates to the backing map and ensure that they stick Map<String, Serializable> mapClone = map.getProtectedMap(); mapClone.put("ONE", "ONE"); assertEquals("Modified the backing directly but value is not visible: ", map.get("ONE"), "ONE"); map.put("TWO", "TWO"); assertTrue("Backing map was changed again!", mapClone == map.getProtectedMap()); mapClone.containsKey("TWO"); } else { // Make sure that the holy map is still acting as the backing map assertTrue("Expect holy map to still be in use: ", map.getProtectedMap() == holyMap); } }