public Object[] getFullElements() { return getSampleKeys(); }
public Object[] getFullElements() { Object[] k = getSampleKeys(); Object[] v = getSampleValues(); return makeEntryArray(k, v); }
/** * 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])); } }
/** * Resets the {@link #map}, {@link #entrySet}, {@link #keySet}, * {@link #values} and {@link #confirmed} fields to full. */ public void resetFull() { this.map = makeFullMap(); views(); this.confirmed = makeConfirmedMap(); Object[] k = getSampleKeys(); Object[] v = getSampleValues(); for (int i = 0; i < k.length; i++) { confirmed.put(k[i], v[i]); } }
/** * 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) { } } } }
@Test public void testMapEntrySetIteratorEntrySetValue() { Object key1 = getSampleKeys()[0]; Object key2 = (getSampleKeys().length == 1 ? getSampleKeys()[0] : getSampleKeys()[1]); Object newValue1 = getNewSampleValues()[0]; Object newValue2 = (getNewSampleValues().length == 1 ? getNewSampleValues()[0] : getNewSampleValues()[1]);
/** * 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(); }
Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) {
Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) {
/** * Helper method to add all the mappings described by * {@link #getSampleKeys()} and {@link #getSampleValues()}. */ public void addSampleMappings(Map m) { Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); for (int i = 0; i < keys.length; i++) { try { m.put(keys[i], values[i]); } catch (NullPointerException exception) { assertTrue("NullPointerException only allowed to be thrown if either the key or value is null.", keys[i] == null || values[i] == null); assertTrue("NullPointerException on null key, but isAllowNullKey is not overridden to return false.", keys[i] == null || !isAllowNullKey()); assertTrue("NullPointerException on null value, but isAllowNullValue is not overridden to return false.", values[i] == null || !isAllowNullValue()); assertTrue("Unknown reason for NullPointer.", false); } } assertEquals("size must reflect number of mappings added.", keys.length, m.size()); }
public void testMapPut() { resetEmpty(); Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); Object[] newValues = getNewSampleValues();
public Object[] getFullElements() { return getSampleKeys(); }
Object[] keys = getSampleKeys(); Object[] values = getSampleValues(); Object[] newValues = getNewSampleValues();
public Object[] getFullElements() { Object[] k = getSampleKeys(); Object[] v = getSampleValues(); return makeEntryArray(k, v); }
/** * Resets the {@link #map}, {@link #entrySet}, {@link #keySet}, * {@link #values} and {@link #confirmed} fields to full. */ public void resetFull() { this.map = makeFullMap(); views(); this.confirmed = makeConfirmedMap(); Object[] k = getSampleKeys(); Object[] v = getSampleValues(); for (int i = 0; i < k.length; i++) { confirmed.put(k[i], v[i]); } }
/** * 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.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(); }