public void addingACollectionOfUniverseElementsToAUniverseElementComposite() throws Exception
{
LinkedList<UniverseElement> testCollection =
new LinkedList<UniverseElement>();
TestUElementComposite testElement2 = new TestUElementComposite();
assertFalse(
"Adding an empty collection to an empty UniverseElementComposite should return false, since the UniverseElementComposite was not modified.",
testElement.addAll( testCollection ) );
assertTrue(
"Having added an empty collection to an empty UniverseElementComposite, the UniverseElementComposite should report itself as being empty.",
testElement.isEmpty() );
testCollection.add( new TestA() );
testCollection.add( new TestB() );
testCollection.add( new TestA() );
assertTrue(
"Adding a non-empty collection of UniverseElements to an empty UniverseElementComposite should return true.",
testElement.addAll( testCollection ) );
assertFalse(
"Having added a non-empty collection of UniverseElements to an empty UniverseElementComposite, the UniverseElementComposite should not longer report itself as being empty.",
testElement.isEmpty() );
assertEquals(
"Having added a non-empty collection to an empty UniverseElementComposite, the collection and the UniverseElementComposite should have the same size.",
testElement.size(), testCollection.size() );
assertTrue(
"UniverseElements added through addAll should report themselves as being contained.",
testCollection.get(0).isContained()
&& testCollection.get(1).isContained()
&& testCollection.get( 2 ).isContained() );
/* Saved for a later test. */
int size = testElement.size();
assertFalse(
"Trying to add a non-empty collection of UniverseElements to a UniverseElementComposite twice should return false the second time.",
testElement.addAll( testCollection ) );
assertEquals(
"Having attempted to add a non-empty collection to an empty UniverseElementComposite twice, the UniverseElementComposite size should not have changed after the second add attempt.",
testElement.size(), size );
testCollection.clear();
testCollection.add( new TestA() );
testCollection.add( new TestA() );
testElement2.addAll( testCollection );
assertFalse(
"Two UniverseElementComposites should not be similar if they were populated with collections of UniverseElements that were, themselves, not similar.",
testElement.similar( testElement2 ) );
testElement2.add( new TestB() );
assertTrue(
"Two UniverseElementComposites should be similar if they have similar elements, regardless of mixing add and addAll statements in building the UniverseElementComposites.",
testElement.similar( testElement2 ) );
assertFalse(
"Attempting to add to a UniverseElementComposite a collection of UniverseElements that have already been added elsewhere should return false.",
testElement.addAll( testCollection ) );
assertFalse(
"Attempting to add to a UniverseElementComposite a collection of UniverseElements that have already been added to a different UniverseElementComposite should cause the potential container UniverseElementComposite to report that it does not contain those elements.",
testElement.contains( testCollection.get( 0 ) )
|| testElement.contains( testCollection.get( 1 ) ) );
testCollection.add( new TestB() );
assertTrue(
"Adding a collection of UniverseElements to a UniverseElementComposite, where the container UniverseElementComposite already contains some, but not all, of the potential child UniverseElements in the collection, should return true.",
testElement2.addAll( testCollection ) );
assertTrue(
"Having added a collection of UniverseElements to a UniverseElementComposite, where the container UniverseElementComposite already contained some, but not all, of the potential child UniverseElements in the collection, the container UniverseElementComposite should report containing all the elements in the added collection.",
testElement2.contains( testCollection.get( 0 ) )
&& testElement2.contains( testCollection.get( 1 ) )
&& testElement2.contains( testCollection.get( 2 ) ) );
assertEquals(
"After a complex series of adding collections of, and individual elements to a UniverseElementComposite, the reported size of the UniverseElementComposite should still be correct (in this case, it should be 4).",
testElement2.size(), 4);
}