/** * Tests {@link Set#hashCode()}. */ public void testSetHashCode() { resetEmpty(); assertEquals("Empty sets have equal hashCodes", getSet().hashCode(), getConfirmedSet().hashCode()); resetFull(); assertEquals("Equal sets have equal hashCodes", getSet().hashCode(), getConfirmedSet().hashCode()); }
/** * Makes an empty collection by invoking {@link #makeEmptySet()}. * * @return an empty collection */ public final Collection makeCollection() { return makeEmptySet(); }
/** * Makes a full collection by invoking {@link #makeFullSet()}. * * @return a full collection */ public final Collection makeFullCollection() { return makeFullSet(); }
/** * Tests {@link Set#equals(Object)}. */ public void testSetEquals() { resetEmpty(); assertEquals("Empty sets should be equal", getSet(), getConfirmedSet()); verify(); Collection set2 = makeConfirmedCollection(); set2.add("foo"); assertTrue("Empty set shouldn't equal nonempty set", !getSet().equals(set2)); resetFull(); assertEquals("Full sets should be equal", getSet(), getConfirmedSet()); verify(); set2.clear(); set2.addAll(Arrays.asList(getOtherElements())); assertTrue("Sets with different contents shouldn't be equal", !getSet().equals(set2)); }
/** * Provides additional verifications for sets. */ public void verify() { super.verify(); assertEquals("Sets should be equal", confirmed, collection); assertEquals("Sets should have equal hashCodes", confirmed.hashCode(), collection.hashCode()); Collection set = makeConfirmedCollection(); Iterator iterator = collection.iterator(); while (iterator.hasNext()) { assertTrue("Set.iterator should only return unique elements", set.add(iterator.next())); } }
/** * Returns a full Set for use in modification testing. * * @return a confirmed full collection */ public Collection makeConfirmedFullCollection() { Collection set = makeConfirmedCollection(); set.addAll(Arrays.asList(getFullElements())); return set; }
/** * Makes a full set by first creating an empty set and then adding * all the elements returned by {@link #getFullElements()}. * * Override if your set does not support the add operation. * * @return a full set */ public Set makeFullSet() { Set set = makeEmptySet(); set.addAll(Arrays.asList(getFullElements())); return set; }