X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=test%2Fnet%2Fsf%2Fopenrocket%2Ffile%2Frocksim%2FLaunchLugHandlerTest.java;fp=test%2Fnet%2Fsf%2Fopenrocket%2Ffile%2Frocksim%2FLaunchLugHandlerTest.java;h=b1b7acfd6fe21a966b8579d792a674060d0a4e6a;hb=198227dc14b96901f3105fd816b6a9b84993adef;hp=0000000000000000000000000000000000000000;hpb=759de538156bbd2810075a5fd14ce9ddb3fbd274;p=debian%2Fopenrocket diff --git a/test/net/sf/openrocket/file/rocksim/LaunchLugHandlerTest.java b/test/net/sf/openrocket/file/rocksim/LaunchLugHandlerTest.java new file mode 100644 index 00000000..b1b7acfd --- /dev/null +++ b/test/net/sf/openrocket/file/rocksim/LaunchLugHandlerTest.java @@ -0,0 +1,184 @@ +/* + * LaunchLugHandlerTest.java + */ +package net.sf.openrocket.file.rocksim; + +import junit.framework.Test; +import junit.framework.TestSuite; +import net.sf.openrocket.aerodynamics.WarningSet; +import net.sf.openrocket.database.Databases; +import net.sf.openrocket.file.simplesax.PlainTextHandler; +import net.sf.openrocket.material.Material; +import net.sf.openrocket.rocketcomponent.BodyTube; +import net.sf.openrocket.rocketcomponent.ExternalComponent; +import net.sf.openrocket.rocketcomponent.LaunchLug; +import net.sf.openrocket.rocketcomponent.RocketComponent; + +import java.util.HashMap; + +/** + * LaunchLugHandler Tester. + * + */ +public class LaunchLugHandlerTest extends BaseRocksimTest { + + /** + * The class under test. + */ + public static final Class classUT = LaunchLugHandler.class; + + /** + * The test class (this class). + */ + public static final Class testClass = LaunchLugHandlerTest.class; + + /** + * Create a test suite of all tests within this test class. + * + * @return a suite of tests + */ + public static Test suite() { + return new TestSuite(LaunchLugHandlerTest.class); + } + + /** + * Test constructor. + * + * @param name the name of the test to run. + */ + public LaunchLugHandlerTest(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 LaunchLugHandler(null); + fail("Should have thrown IllegalArgumentException"); + } + catch (IllegalArgumentException iae) { + //success + } + + BodyTube tube = new BodyTube(); + LaunchLugHandler handler = new LaunchLugHandler(tube); + LaunchLug component = (LaunchLug) getField(handler, "lug"); + 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 LaunchLugHandler(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(); + LaunchLugHandler handler = new LaunchLugHandler(tube); + LaunchLug component = (LaunchLug) getField(handler, "lug"); + HashMap attributes = new HashMap(); + WarningSet warnings = new WarningSet(); + + handler.closeElement("OD", attributes, "-1", warnings); + assertEquals(0d, component.getRadius()); + handler.closeElement("OD", attributes, "0", warnings); + assertEquals(0d, component.getRadius()); + handler.closeElement("OD", attributes, "75", warnings); + assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getRadius()); + handler.closeElement("OD", attributes, "foo", warnings); + assertEquals(1, warnings.size()); + warnings.clear(); + + handler.closeElement("ID", attributes, "-1", warnings); + assertEquals(0d, component.getInnerRadius()); + handler.closeElement("ID", attributes, "0", warnings); + assertEquals(0d, component.getInnerRadius()); + handler.closeElement("ID", attributes, "75", warnings); + assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius()); + handler.closeElement("ID", attributes, "foo", warnings); + assertEquals(1, warnings.size()); + warnings.clear(); + + handler.closeElement("Len", attributes, "-1", warnings); + assertEquals(0d, component.getLength()); + handler.closeElement("Len", attributes, "10", warnings); + assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength()); + handler.closeElement("Len", attributes, "10.0", warnings); + assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength()); + handler.closeElement("Len", attributes, "foo", warnings); + assertEquals(1, warnings.size()); + warnings.clear(); + + handler.closeElement("FinishCode", attributes, "-1", warnings); + assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish()); + handler.closeElement("FinishCode", attributes, "100", warnings); + assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish()); + handler.closeElement("FinishCode", attributes, "foo", warnings); + assertEquals(1, warnings.size()); + warnings.clear(); + + handler.closeElement("Name", attributes, "Test Name", warnings); + assertEquals("Test Name", component.getName()); + } + + /** + * Method: setRelativePosition(RocketComponent.Position position) + * + * @throws Exception thrown if something goes awry + */ + public void testSetRelativePosition() throws Exception { + BodyTube tube = new BodyTube(); + LaunchLugHandler handler = new LaunchLugHandler(tube); + LaunchLug component = (LaunchLug) getField(handler, "lug"); + 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 LaunchLugHandler(new BodyTube()).getComponent() instanceof LaunchLug); + } + + /** + * Method: getMaterialType() + * + * @throws Exception thrown if something goes awry + */ + public void testGetMaterialType() throws Exception { + assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube()).getMaterialType()); + } + + +}