public void resetFull() { empty = false; super.resetFull(); }
public void resetFull() { MapAbstractTest.this.resetFull(); collection = map.entrySet(); TestMapEntrySet.this.confirmed = MapAbstractTest.this.confirmed.entrySet(); }
public void resetFull() { MapAbstractTest.this.resetFull(); collection = map.keySet(); TestMapKeySet.this.confirmed = MapAbstractTest.this.confirmed.keySet(); }
public void resetFull() { MapAbstractTest.this.resetFull(); collection = map.values(); TestMapValues.this.confirmed = MapAbstractTest.this.confirmed.values(); }
@Test public void testEntrySetContains3() { resetFull(); Set entrySet = map.entrySet(); Map.Entry entry = (Map.Entry) entrySet.iterator().next(); HashMap temp = new HashMap(); temp.put(entry.getKey(), "A VERY DIFFERENT VALUE"); Map.Entry test = (Map.Entry) temp.entrySet().iterator().next(); assertEquals(false, entrySet.contains(test)); }
@Test public void testEntrySetContains1() { resetFull(); Set entrySet = map.entrySet(); Map.Entry entry = (Map.Entry) entrySet.iterator().next(); assertEquals(true, entrySet.contains(entry)); }
@Test public void testEntrySetContains2() { resetFull(); Set entrySet = map.entrySet(); Map.Entry entry = (Map.Entry) entrySet.iterator().next(); Map.Entry test = cloneMapEntry(entry); assertEquals(true, entrySet.contains(test)); }
@Test public void testEntrySetRemove3() { if (!isRemoveSupported()) { return; } resetFull(); int size = map.size(); Set entrySet = map.entrySet(); Map.Entry entry = (Map.Entry) entrySet.iterator().next(); Object key = entry.getKey(); HashMap temp = new HashMap(); temp.put(entry.getKey(), "A VERY DIFFERENT VALUE"); Map.Entry test = (Map.Entry) temp.entrySet().iterator().next(); assertEquals(false, entrySet.remove(test)); assertEquals(true, map.containsKey(key)); assertEquals(size, map.size()); }
@Test public void testEntrySetRemove1() { if (!isRemoveSupported()) { return; } resetFull(); int size = map.size(); Set entrySet = map.entrySet(); Map.Entry entry = (Map.Entry) entrySet.iterator().next(); Object key = entry.getKey(); assertEquals(true, entrySet.remove(entry)); assertEquals(false, map.containsKey(key)); assertEquals(size - 1, map.size()); }
/** * Tests Map.hashCode() */ @Test public void testMapHashCode() { resetEmpty(); assertTrue("Empty maps have different hashCodes.", map.hashCode() == confirmed.hashCode()); resetFull(); assertTrue("Equal maps have different hashCodes.", map.hashCode() == confirmed.hashCode()); }
@Test public void testEntrySetRemove2() { if (!isRemoveSupported()) { return; } resetFull(); int size = map.size(); Set entrySet = map.entrySet(); Map.Entry entry = (Map.Entry) entrySet.iterator().next(); Object key = entry.getKey(); Map.Entry test = cloneMapEntry(entry); assertEquals(true, entrySet.remove(test)); assertEquals(false, map.containsKey(key)); assertEquals(size - 1, map.size()); }
/** * Tests that the {@link Map#keySet} set is backed by * the underlying map by removing from the keySet set * and testing if the key was removed from the map. */ @Test public void testKeySetRemoveChangesMap() { resetFull(); Object[] sampleKeys = getSampleKeys(); Set keys = map.keySet(); for (int i = 0; i < sampleKeys.length; i++) { try { keys.remove(sampleKeys[i]); } catch (UnsupportedOperationException e) { // if key.remove is unsupported, just skip this test return; } assertTrue( "Key should have been removed from the underlying map.", !map.containsKey(sampleKeys[i])); } }
/** * Tests Map.equals(Object) */ @Test public void testMapEquals() { resetEmpty(); assertTrue("Empty maps unequal.", map.equals(confirmed)); verifyAll(); resetFull(); assertTrue("Full maps unequal.", map.equals(confirmed)); verifyAll(); resetFull(); // modify the HashMap created from the full map and make sure this // change results in map.equals() to return false. Iterator iter = confirmed.keySet().iterator(); iter.next(); iter.remove(); assertTrue("Different maps equal.", !map.equals(confirmed)); resetFull(); assertTrue("equals(null) returned true.", !map.equals(null)); assertTrue("equals(new Object()) returned true.", !map.equals(new Object())); verifyAll(); }
/** * Tests Map.isEmpty() */ @Test public void testMapIsEmpty() { resetEmpty(); assertEquals("Map.isEmpty() should return true with an empty map", true, map.isEmpty()); verifyAll(); resetFull(); assertEquals("Map.isEmpty() should return false with a non-empty map", false, map.isEmpty()); verifyAll(); }
/** * Tests Map.size() */ @Test public void testMapSize() { resetEmpty(); assertEquals("Map.size() should be 0 with an empty map", 0, map.size()); verifyAll(); resetFull(); assertEquals("Map.size() should equal the number of entries in the map", getSampleKeys().length, map.size()); verifyAll(); }
/** * Tests Map.put(null, value) */ @Test public void testMapPutNullValue() { resetFull(); Object[] keys = getSampleKeys(); if (isPutAddSupported()) { if (isAllowNullValue()) { map.put(keys[0], null); } else { try { map.put(keys[0], null); fail("put(key, null) should throw NPE/IAE"); } catch (NullPointerException ex) { } catch (IllegalArgumentException ex) { } } } }
/** * Tests Map.toString(). Since the format of the string returned by the * toString() method is not defined in the Map interface, there is no * common way to test the results of the toString() method. Thereforce, * it is encouraged that Map implementations override this test with one * that checks the format matches any format defined in its API. This * default implementation just verifies that the toString() method does * not return null. */ @Test public void testMapToString() { resetEmpty(); assertTrue("Empty map toString() should not return null", map.toString() != null); verifyAll(); resetFull(); assertTrue("Empty map toString() should not return null", map.toString() != null); verifyAll(); }
/** * Tests Map.get(Object) */ @Test public void testMapGet() { resetEmpty(); Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); for (Object key : keys) { assertTrue("Empty map.get() should return null.", map.get(key) == null); } verifyAll(); resetFull(); for (int i = 0; i < keys.length; i++) { assertEquals("Full map.get() should return value from mapping.", values[i], map.get(keys[i])); } }
/** * Tests Map.containsKey(Object) by verifying it returns false for all * sample keys on a map created using an empty map and returns true for * all sample keys returned on a full map. */ @Test public void testMapContainsKey() { Object[] keys = getSampleKeys(); resetEmpty(); for (Object key : keys) { assertTrue("Map must not contain key when map is empty", !map.containsKey(key)); } verifyAll(); resetFull(); for (Object key : keys) { assertTrue("Map must contain key for a mapping in the map. Missing: " + key, map.containsKey(key)); } verifyAll(); }
/** * Tests Map.containsValue(Object) by verifying it returns false for all * sample values on an empty map and returns true for all sample values on * a full map. */ @Test public void testMapContainsValue() { Object[] values = getSampleValues(); resetEmpty(); for (Object value : values) { assertTrue("Empty map must not contain value", !map.containsValue(value)); } verifyAll(); resetFull(); for (Object value : values) { assertTrue("Map must contain value for a mapping in the map.", map.containsValue(value)); } verifyAll(); }