X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=test%2Fnet%2Fsf%2Fopenrocket%2Ffile%2Frocksim%2FMassObjectHandlerTest.java;fp=test%2Fnet%2Fsf%2Fopenrocket%2Ffile%2Frocksim%2FMassObjectHandlerTest.java;h=2bd30b4a4363384c8345d86371c0a0f632faeefa;hb=198227dc14b96901f3105fd816b6a9b84993adef;hp=0000000000000000000000000000000000000000;hpb=759de538156bbd2810075a5fd14ce9ddb3fbd274;p=debian%2Fopenrocket diff --git a/test/net/sf/openrocket/file/rocksim/MassObjectHandlerTest.java b/test/net/sf/openrocket/file/rocksim/MassObjectHandlerTest.java new file mode 100644 index 00000000..2bd30b4a --- /dev/null +++ b/test/net/sf/openrocket/file/rocksim/MassObjectHandlerTest.java @@ -0,0 +1,166 @@ +/* + * MassObjectHandlerTest.java + */ +package net.sf.openrocket.file.rocksim; + +import junit.framework.Test; +import junit.framework.TestSuite; +import net.sf.openrocket.file.simplesax.PlainTextHandler; +import net.sf.openrocket.material.Material; +import net.sf.openrocket.rocketcomponent.BodyTube; +import net.sf.openrocket.rocketcomponent.MassComponent; +import net.sf.openrocket.rocketcomponent.RocketComponent; +import net.sf.openrocket.rocketcomponent.Stage; +import net.sf.openrocket.rocketcomponent.NoseCone; +import net.sf.openrocket.rocketcomponent.Transition; +import net.sf.openrocket.aerodynamics.WarningSet; + +import java.util.HashMap; + +/** + * MassObjectHandler Tester. + * + */ +public class MassObjectHandlerTest extends BaseRocksimTest { + + /** + * The class under test. + */ + public static final Class classUT = MassObjectHandler.class; + + /** + * The test class (this class). + */ + public static final Class testClass = MassObjectHandlerTest.class; + + /** + * Create a test suite of all tests within this test class. + * + * @return a suite of tests + */ + public static Test suite() { + return new TestSuite(MassObjectHandlerTest.class); + } + + /** + * Test constructor. + * + * @param name the name of the test to run. + */ + public MassObjectHandlerTest(String name) { + super(name); + } + + /** + * Setup the fixture. + */ + public void setUp() throws Exception { + super.setUp(); + } + + /** + * Teardown the fixture. + */ + public void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Method: constructor + * + * @throws Exception thrown if something goes awry + */ + public void testConstructor() throws Exception { + + try { + new MassObjectHandler(null); + fail("Should have thrown IllegalArgumentException"); + } + catch (IllegalArgumentException iae) { + //success + } + + BodyTube tube = new BodyTube(); + MassObjectHandler handler = new MassObjectHandler(tube); + MassComponent component = (MassComponent) getField(handler, "mass"); + assertContains(component, tube.getChildren()); + } + + /** + * Method: openElement(String element, HashMap attributes, WarningSet warnings) + * + * @throws Exception thrown if something goes awry + */ + public void testOpenElement() throws Exception { + assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(new BodyTube()).openElement(null, null, null)); + } + + /** + * + * Method: closeElement(String element, HashMap attributes, String content, WarningSet warnings) + * + * @throws Exception thrown if something goes awry + */ + public void testCloseElement() throws Exception { + BodyTube tube = new BodyTube(); + HashMap attributes = new HashMap(); + WarningSet warnings = new WarningSet(); + + MassObjectHandler handler = new MassObjectHandler(tube); + MassComponent component = (MassComponent) getField(handler, "mass"); + + handler.closeElement("Len", attributes, "-1", warnings); + assertEquals(0d, component.getLength()); + handler.closeElement("Len", attributes, "10", warnings); + assertEquals(10d / (MassObjectHandler.MASS_LEN_FUDGE_FACTOR * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH) + , component.getLength()); + handler.closeElement("Len", attributes, "10.0", warnings); + assertEquals(10d / (MassObjectHandler.MASS_LEN_FUDGE_FACTOR * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH) + , component.getLength()); + handler.closeElement("Len", attributes, "foo", warnings); + assertEquals(1, warnings.size()); + warnings.clear(); + + handler.closeElement("KnownMass", attributes, "-1", warnings); + assertEquals(0d, component.getComponentMass()); + handler.closeElement("KnownMass", attributes, "100", warnings); + assertEquals(100d / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS, component.getComponentMass()); + handler.closeElement("KnownMass", attributes, "foo", warnings); + assertEquals(1, warnings.size()); + warnings.clear(); + + } + + /** + * Method: setRelativePosition(RocketComponent.Position position) + * + * @throws Exception thrown if something goes awry + */ + public void testSetRelativePosition() throws Exception { + BodyTube tube = new BodyTube(); + MassObjectHandler handler = new MassObjectHandler(tube); + MassComponent component = (MassComponent) getField(handler, "mass"); + handler.setRelativePosition(RocketComponent.Position.ABSOLUTE); + assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition()); + } + + /** + * Method: getComponent() + * + * @throws Exception thrown if something goes awry + */ + public void testGetComponent() throws Exception { + assertTrue(new MassObjectHandler(new BodyTube()).getComponent() instanceof MassComponent); + } + + /** + * Method: getMaterialType() + * + * @throws Exception thrown if something goes awry + */ + public void testGetMaterialType() throws Exception { + assertEquals(Material.Type.BULK, new MassObjectHandler(new BodyTube()).getMaterialType()); + } + + +}