* @throws Exception
*/
@Test
public void addingACollectionWithNullToAUniverseElementComposite() throws Exception
{
TestUElement element1 = new TestUElement();
testElement.add (element1 );
LinkedList<UniverseElement> testCollection =
new LinkedList<UniverseElement>();
testCollection.add( null );
try
{
testElement.addAll( testCollection );
fail("Adding a collection containing only nulls to a UniverseElementComposite should throw an exception, but did not.");
}
catch ( NullPointerException e )
{
}
catch ( Exception e )
{
fail("Adding a collection containing only nulls to a UniverseElementComposite should throw only a NullPointerException, but a(n) " + e.getClass().getName() + " exception was thrown.");
}
assertTrue(
"After failing to add a collection containing only nulls to a UniverseElementComposite, the UniverseElementComposite should not have changed.",
testElement.size() == 1
&& testElement.contains( element1 ) );
testCollection.clear();
testCollection.add( new TestUElement() );
testCollection.add( null );
testCollection.add( new TestUElementComposite() );
try
{
testElement.addAll( testCollection );
fail("Adding a collection with a null reference and other valid elements should throw a NullPointerException due to the null reference, but did not.");
}
catch ( NullPointerException e )
{
}
catch ( Exception e )
{
fail("Adding a collection containing a null to a UniverseElementComposite should throw only a NullPointerException, but a(n) " + e.getClass().getName() + " exception was thrown.");
}
assertTrue(
"After failing to add a collection with a null reference to a UniverseElementComposite, the UniverseElementComposite should not have changed.",
testElement.size() == 1
&& testElement.contains( element1 ) );
testCollection.clear();
testCollection.add( new TestUElementComposite() );
testCollection.add( new TestUElement() );
testCollection.add( null );
try
{
testElement.addAll( testCollection );
fail("Adding a collection with valid elements and a null reference as the last element should throw a NullPointerException due to the null reference, but did not.");
}
catch ( NullPointerException e )
{
}
catch ( Exception e )
{
fail("Adding a collection containing a null reference as the last element to a UniverseElementComposite should throw only a NullPointerException, but a(n) " + e.getClass().getName() + " exception was thrown.");
}
assertTrue(
"After failing to add a collection with a null reference to a UniverseElementComposite, the UniverseElementComposite should not have changed.",
testElement.size() == 1
&& testElement.contains( element1 ) );
testCollection.clear();
testCollection.add( null );
testCollection.add( new TestUElementComposite() );
testCollection.add( new TestUElement() );
try
{
testElement.addAll( testCollection );
fail("Adding a collection with valid elements and a null reference as the first element should throw a NullPointerException due to the null reference, but did not.");