Package etherstrategy.simulation

Examples of etherstrategy.simulation.TestUElementComposite


        TestC element6 = new TestC();
        TestC element7 = new TestC();
        TestDerivedFromC element8 = new TestDerivedFromC();
        TestDerivedFromC element9 = new TestDerivedFromC();
        TestUElement element10 = new TestUElement();
        TestUElementComposite element11 = new TestUElementComposite();

        element1.add( element2 );
        element1.add( element7 );
        element1.add( element11 );
        element1.setCenter( 1, 1, 1 );

        element2.add( element8 );
        element2.setCenter( 2, 2, 2 );

        element3.setCenter( 3, 3, 3 );

        element4.setCenter( 4, 4, 4 );
        element4.add( element10 );

        element5.setCenter( 5, 5, 5 );

        element6.add( element3 );
        element6.add( element5 );
        element6.add( element9 );
        element6.setCenter( 6, 6, 6 );

        element7.setCenter( 7, 7, 7 );

        element8.setCenter( 8, 8, 8 );

        element9.setCenter( 9, 9, 9 );

        TestUElementComposite copiedElement =
            new TestUElementComposite(testElement);

        assertNotNull(
                "Constructing a copy of an empty UniverseElementComposite should not result in a null UniverseElementComposite.",
                copiedElement );

        assertTrue(
                "A copy of an empty UniverseElementComposite should, itself, be empty.",
                copiedElement.isEmpty() );

        testElement.add( element1 );
        testElement.add( element4 );
        testElement.add( element6 );

        copiedElement = new TestUElementComposite(testElement);

        assertNotNull(
                "After creating a new UniverseElementComposite through a copy constructor, the new UniverseElementComposite should not be null.",
                copiedElement );

        assertTrue(
                "After creating a new UniverseElementComposite through a copy constructor, the copy should be similar to the original.",
                testElement.similar( copiedElement ) );

        assertEquals(
                "After creating a new UniverseElementComposite through a copy constructor, the centers of the two element should be equal.",
                testElement.getCenter(), copiedElement.getCenter() );

        element8.add( new TestC() );

        assertFalse(
                "After creating a new UniverseElementComposite through a copy constructor, and then adding a new UniverseElement child deep in the structure of the original UniverseElementComposite, the two UniverseElementComposites should no longer be similar.",
                testElement.similar( copiedElement ) );

        element8.clear();

        assertTrue(
                "Having created a new UniverseElementComposite through a copy constructor and then added a child deep inside the structure of the original UniverseElementComposite (thereby making the two UniverseElementComposites dissimilar), removing that added child should make the two UniverseElementComposites similar again.",
                testElement.similar( copiedElement ) );

        element8.setCenter( 20, 20, 20 );

        assertFalse(
                "After creating a new UniverseElementComposite through a copy constructor and then changing the center of one of the children deep in the structure of the original UniverseElementComposite, the two elements should not longer be similar.",
                testElement.similar( copiedElement ) );

        /* This is almost certainly redundant. */
        testElement.setCenter( 1, 1, 1 );

        assertFalse(
                "After creating a new UniverseElementComposite through a copy constructor and then changing the center of the original UniverseElementComposite, the centers of the two elements should not be equal.",
                testElement.getCenter() == copiedElement.getCenter() );
    }
View Full Code Here


        testElement.add(elementNCT);

        try
        {
            new TestUElementComposite(testElement);
            fail("Attempting to copy a child UniverseElement that does not have a copy constructor should throw an exception, but did not.");
        }
        catch ( NoSuchMethodException e )
        {
           
        }
        catch ( Exception e )
        {
            fail("Attempting to copy a child UniverseElement that does not have a copy constructor should only throw a NoSuchMethodException, but a(n) " + e.getClass().getName() + " was thrown.");
        }

        testElement.clear();
        testElement.add( elementDACT );

        /* Hmm, doesn't work this way. */
        /*
        try
        {
            new TestUElementComposite(testElement);
            fail("Attempting to copy a child UniverseElement that only has access to the public copy constructor of an abstract superclass should throw an exception, but did not.");
        }
        catch ( InstantiationException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to copy a child UniverseElement that only has access to the public copy constructor of an abstract superclass should only throw an InstantiationException, but a(n) " + e.getClass().getName() + "was thrown.");
        }
        */
        try
        {
            new TestUElementComposite(testElement);
            fail("Attempting to copy a child UniverseElement that only has access to the public copy constructor of an abstract superclass should throw an exception, but did not.");
        }
        catch ( NoSuchMethodException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to copy a child UniverseElement that only has access to the public copy constructor of an abstract superclass should only throw a NoSuchMethodException, but a(n) " + e.getClass().getName() + "was thrown.");
        }

        testElement.clear();
        testElement.add( elementPCT );

        /* ARG!  This also doesn't work this way! */
        /*
        try
        {
            new TestUElementComposite(testElement);
            fail("Attempting to copy a child UniverseElement that only has non-public copy constructors should throw an exception, but did not.");
        }
        catch ( IllegalAccessException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to copy a child UniverseElement that only has non-public copy constructors should only throw an IllegalAccessException, but a(n) " + e.getClass().getName() + " was thrown.");
        }
        */
        try
        {
            new TestUElementComposite(testElement);
            fail("Attempting to copy a child UniverseElement that only has non-public copy constructors should throw an exception, but did not.");
        }
        catch ( NoSuchMethodException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to copy a child UniverseElement that only has non-public copy constructors should only throw a NoSuchMethodException, but a(n) " + e.getClass().getName() + " was thrown.");
        }

        testElement.clear();
        goodElement.add(elementNCT);
        testElement.add(goodElement);

        try
        {
            new TestUElementComposite(testElement);
            fail("Attempting to copy a child UniverseElement that, itself, has a copy constructor-less child should throw an exception, but did not.");
        }
        catch ( InvocationTargetException e )
        {
            if ( e.getCause().getClass() != NoSuchMethodException.class )
View Full Code Here

    @Test
    public void checkingForUniverseElementLeafState() throws Exception
    {
        assertFalse(
                "UniverseElementComposites that do not override isLeaf() should always return false when that method is called.",
                (new TestUElementComposite()).isLeaf()
                || (new TestA()).isLeaf()
                || (new TestC()).isLeaf()
                || (new TestDerivedFromC()).isLeaf() );
    }
View Full Code Here

TOP

Related Classes of etherstrategy.simulation.TestUElementComposite

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.