if (!isRemoveSupported()) return; resetEmpty(); Object[] elements = getFullElements(); for (int i = 0; i < elements.length; i++) { assertTrue("Shouldn't remove nonexistent element", !collection.remove(elements[i])); verifyAll(); Object[] other = getOtherElements(); resetFull(); for (int i = 0; i < other.length; i++) { assertTrue("Shouldn't remove nonexistent other element", !collection.remove(other[i])); verifyAll(); resetFull(); assertTrue("Collection should remove extant element: " + elements[i], collection.remove(elements[i])); if(!areEqualElementsDistinguishable()) { confirmed.remove(elements[i]); verifyAll();
if (!isRemoveSupported()) return; resetEmpty(); try { collection.iterator().remove(); verifyAll(); verifyAll(); resetFull(); int size = collection.size(); Iterator iter = collection.iterator(); o = cloneMapEntry((Map.Entry) o); if(!areEqualElementsDistinguishable()) { confirmed.remove(o); verifyAll(); collection.isEmpty()); resetFull(); iter = collection.iterator(); iter.next();
/** * Returns an array of objects that are contained in a collection * produced by {@link #makeFullCollection()}. Every element in the * returned array <I>must</I> be an element in a full collection.<P> * The default implementation returns a heterogenous array of * objects with some duplicates. null is added if allowed. * Override if you require specific testing elements. Note that if you * override {@link #makeFullCollection()}, you <I>must</I> override * this method to reflect the contents of a full collection. */ public Object[] getFullElements() { if (isNullSupported()) { ArrayList list = new ArrayList(); list.addAll(Arrays.asList(getFullNonNullElements())); list.add(4, null); return list.toArray(); } else { return (Object[]) getFullNonNullElements().clone(); } }
/** * Returns a full collection to be used for testing. The collection * returned by this method should contain every element returned by * {@link #getFullElements()}. The default implementation, in fact, * simply invokes {@code addAll} on an empty collection with * the results of {@link #getFullElements()}. Override this default * if your collection doesn't support addAll. */ public Collection makeFullCollection() { Collection c = makeCollection(); c.addAll(Arrays.asList(getFullElements())); return c; }
/** * Test {@link Collection#clear()}. */ @Test public void testCollectionClear() { if (!isRemoveSupported()) return; resetEmpty(); collection.clear(); // just to make sure it doesn't raise anything verifyAll(); resetFull(); collection.clear(); confirmed.clear(); verifyAll(); }
if (!isFailFastSupported()) return; if (isAddSupported()) { resetFull(); try { Iterator iter = collection.iterator(); Object o = getOtherElements()[0]; collection.add(o); confirmed.add(o); verifyAll(); resetFull(); try { Iterator iter = collection.iterator(); collection.addAll(Arrays.asList(getOtherElements())); confirmed.addAll(Arrays.asList(getOtherElements())); iter.next(); fail("next after addAll should raise ConcurrentModification"); verifyAll(); if (!isRemoveSupported()) return; resetFull(); try { Iterator iter = collection.iterator(); resetFull();
/** * Tests {@link Collection#add(Object)}. */ @Test public void testCollectionAdd() { if (!isAddSupported()) return; Object[] elements = getFullElements(); for (int i = 0; i < elements.length; i++) { resetEmpty(); boolean r = collection.add(elements[i]); confirmed.add(elements[i]); verifyAll(); assertTrue("Empty collection changed after add", r); assertEquals("Collection size is 1 after first add", 1, collection.size()); } resetEmpty(); int size = 0; for (int i = 0; i < elements.length; i++) { boolean r = collection.add(elements[i]); confirmed.add(elements[i]); verifyAll(); if (r) size++; assertEquals("Collection size should grow after add", size, collection.size()); assertTrue("Collection should contain added element", collection.contains(elements[i])); } }
/** * Returns an array of elements that are <I>not</I> contained in a * full collection. Every element in the returned array must * not exist in a collection returned by {@link #makeFullCollection()}. * The default implementation returns a heterogenous array of elements * without null. Note that some of the tests add these elements * to an empty or full collection, so if your collection restricts * certain kinds of elements, you should override this method. */ public Object[] getOtherElements() { return getOtherNonNullElements(); }
Object[] elements; resetEmpty(); elements = getFullElements(); for(int i = 0; i < elements.length; i++) { assertTrue("Empty collection shouldn't contain element[" + i + "]", verifyAll(); elements = getOtherElements(); for(int i = 0; i < elements.length; i++) { assertTrue("Empty collection shouldn't contain element[" + i + "]", verifyAll(); resetFull(); elements = getFullElements(); for(int i = 0; i < elements.length; i++) { assertTrue("Full collection should contain element[" + i + "]", verifyAll(); resetFull(); elements = getOtherElements(); for(int i = 0; i < elements.length; i++) { assertTrue("Full collection shouldn't contain element",
if (!isFailFastSupported()) return; if (isAddSupported()) { resetFull(); try { Iterator iter = collection.iterator(); Object o = getOtherElements()[0]; collection.add(o); confirmed.add(o); verifyAll(); resetFull(); try { Iterator iter = collection.iterator(); collection.addAll(Arrays.asList(getOtherElements())); confirmed.addAll(Arrays.asList(getOtherElements())); iter.next(); fail("next after addAll should raise ConcurrentModification"); verifyAll(); if (!isRemoveSupported()) return; resetFull(); try { Iterator iter = collection.iterator(); resetFull();
if (isRemoveSupported()) return; resetEmpty(); try { collection.clear(); verifyAll(); verifyAll(); verifyAll(); verifyAll(); resetFull(); try { Iterator iterator = collection.iterator(); verifyAll();
/** * Tests {@link Collection#add(Object)}. */ @Test public void testCollectionAdd() { if (!isAddSupported()) return; Object[] elements = getFullElements(); for (int i = 0; i < elements.length; i++) { resetEmpty(); boolean r = collection.add(elements[i]); confirmed.add(elements[i]); verifyAll(); assertTrue("Empty collection changed after add", r); assertEquals("Collection size is 1 after first add", 1, collection.size()); } resetEmpty(); int size = 0; for (int i = 0; i < elements.length; i++) { boolean r = collection.add(elements[i]); confirmed.add(elements[i]); verifyAll(); if (r) size++; assertEquals("Collection size should grow after add", size, collection.size()); assertTrue("Collection should contain added element", collection.contains(elements[i])); } }
/** * Returns a full collection to be used for testing. The collection * returned by this method should contain every element returned by * {@link #getFullElements()}. The default implementation, in fact, * simply invokes {@code addAll} on an empty collection with * the results of {@link #getFullElements()}. Override this default * if your collection doesn't support addAll. */ public Collection makeFullCollection() { Collection c = makeCollection(); c.addAll(Arrays.asList(getFullElements())); return c; }
/** * Returns an array of elements that are <I>not</I> contained in a * full collection. Every element in the returned array must * not exist in a collection returned by {@link #makeFullCollection()}. * The default implementation returns a heterogenous array of elements * without null. Note that some of the tests add these elements * to an empty or full collection, so if your collection restricts * certain kinds of elements, you should override this method. */ public Object[] getOtherElements() { return getOtherNonNullElements(); }
if (!isRemoveSupported()) return; resetEmpty(); try { collection.iterator().remove(); verifyAll(); verifyAll(); resetFull(); int size = collection.size(); Iterator iter = collection.iterator(); o = cloneMapEntry((Map.Entry) o); if(!areEqualElementsDistinguishable()) { confirmed.remove(o); verifyAll(); collection.isEmpty()); resetFull(); iter = collection.iterator(); iter.next();
/** * Test {@link Collection#clear()}. */ @Test public void testCollectionClear() { if (!isRemoveSupported()) return; resetEmpty(); collection.clear(); // just to make sure it doesn't raise anything verifyAll(); resetFull(); collection.clear(); confirmed.clear(); verifyAll(); }
/** * Returns an array of objects that are contained in a collection * produced by {@link #makeFullCollection()}. Every element in the * returned array <I>must</I> be an element in a full collection.<P> * The default implementation returns a heterogenous array of * objects with some duplicates. null is added if allowed. * Override if you require specific testing elements. Note that if you * override {@link #makeFullCollection()}, you <I>must</I> override * this method to reflect the contents of a full collection. */ public Object[] getFullElements() { if (isNullSupported()) { ArrayList list = new ArrayList(); list.addAll(Arrays.asList(getFullNonNullElements())); list.add(4, null); return list.toArray(); } else { return (Object[]) getFullNonNullElements().clone(); } }
resetEmpty(); Collection col = new HashSet(); assertTrue("Every Collection should contain all elements of an " + "empty Collection.", collection.containsAll(col)); col.addAll(Arrays.asList(getOtherElements())); assertTrue("Empty Collection shouldn't contain all elements of " + "a non-empty Collection.", !collection.containsAll(col)); verifyAll(); resetFull(); assertTrue("Full collection shouldn't contain other elements", !collection.containsAll(col)); col.addAll(Arrays.asList(getFullElements())); assertTrue("Full collection should containAll full elements", collection.containsAll(col)); verifyAll(); int min = (getFullElements().length < 2 ? 0 : 2); int max = (getFullElements().length == 1 ? 1 : (getFullElements().length <= 5 ? getFullElements().length - 1 : 5)); col = Arrays.asList(getFullElements()).subList(min, max); assertTrue("Full collection should containAll partial full " + "elements", collection.containsAll(col)); verifyAll();
if (isRemoveSupported()) return; resetEmpty(); try { collection.clear(); verifyAll(); verifyAll(); verifyAll(); verifyAll(); resetFull(); try { Iterator iterator = collection.iterator(); verifyAll();
if (isAddSupported()) return; resetEmpty(); try { collection.add(new Object()); verifyAll(); collection.addAll(Arrays.asList(getFullElements())); fail("Emtpy collection should not support addAll."); } catch (UnsupportedOperationException e) { verifyAll(); resetFull(); try { collection.add(new Object()); verifyAll(); collection.addAll(Arrays.asList(getOtherElements())); fail("Full collection should not support addAll."); } catch (UnsupportedOperationException e) { verifyAll();