2 * BodyTubeHandlerTest.java
4 package net.sf.openrocket.file.rocksim;
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8 import net.sf.openrocket.aerodynamics.WarningSet;
9 import net.sf.openrocket.file.simplesax.PlainTextHandler;
10 import net.sf.openrocket.material.Material;
11 import net.sf.openrocket.rocketcomponent.BodyTube;
12 import net.sf.openrocket.rocketcomponent.ExternalComponent;
13 import net.sf.openrocket.rocketcomponent.Stage;
15 import java.util.HashMap;
18 * BodyTubeHandler Tester.
21 public class BodyTubeHandlerTest extends RocksimTestBase {
24 * The class under test.
26 public static final Class classUT = BodyTubeHandler.class;
29 * The test class (this class).
31 public static final Class testClass = BodyTubeHandlerTest.class;
34 * Create a test suite of all tests within this test class.
36 * @return a suite of tests
38 public static Test suite() {
39 return new TestSuite(BodyTubeHandlerTest.class);
45 * @param name the name of the test to run.
47 public BodyTubeHandlerTest(String name) {
54 public void setUp() throws Exception {
59 * Teardown the fixture.
61 public void tearDown() throws Exception {
69 * @throws Exception thrown if something goes awry
71 public void testConstructor() throws Exception {
74 new BodyTubeHandler(null, new WarningSet());
75 fail("Should have thrown IllegalArgumentException");
77 catch (IllegalArgumentException iae) {
81 Stage stage = new Stage();
82 BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
83 BodyTube component = (BodyTube) getField(handler, "bodyTube");
84 assertContains(component, stage.getChildren());
88 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
90 * @throws Exception thrown if something goes awry
92 public void testOpenElement() throws Exception {
93 assertEquals(PlainTextHandler.INSTANCE, new BodyTubeHandler(new Stage(), new WarningSet()).openElement(null, null, null));
94 assertNotNull(new BodyTubeHandler(new Stage(), new WarningSet()).openElement("AttachedParts", null, null));
99 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
101 * @throws Exception thrown if something goes awry
103 public void testCloseElement() throws Exception {
104 Stage stage = new Stage();
105 BodyTubeHandler handler = new BodyTubeHandler(stage, new WarningSet());
106 BodyTube component = (BodyTube) getField(handler, "bodyTube");
107 HashMap<String, String> attributes = new HashMap<String, String>();
108 WarningSet warnings = new WarningSet();
110 handler.closeElement("OD", attributes, "-1", warnings);
111 assertEquals(0d, component.getInnerRadius());
112 handler.closeElement("OD", attributes, "0", warnings);
113 assertEquals(0d, component.getInnerRadius());
114 handler.closeElement("OD", attributes, "75", warnings);
115 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
116 handler.closeElement("OD", attributes, "foo", warnings);
117 assertEquals(1, warnings.size());
120 handler.closeElement("ID", attributes, "-1", warnings);
121 assertEquals(0d, component.getInnerRadius());
122 handler.closeElement("ID", attributes, "0", warnings);
123 assertEquals(0d, component.getInnerRadius());
124 handler.closeElement("ID", attributes, "75", warnings);
125 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
126 handler.closeElement("ID", attributes, "foo", warnings);
127 assertEquals(1, warnings.size());
130 handler.closeElement("Len", attributes, "-1", warnings);
131 assertEquals(0d, component.getLength());
132 handler.closeElement("Len", attributes, "10", warnings);
133 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
134 handler.closeElement("Len", attributes, "10.0", warnings);
135 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
136 handler.closeElement("Len", attributes, "foo", warnings);
137 assertEquals(1, warnings.size());
140 handler.closeElement("IsMotorMount", attributes, "1", warnings);
141 assertTrue(component.isMotorMount());
142 handler.closeElement("IsMotorMount", attributes, "0", warnings);
143 assertFalse(component.isMotorMount());
144 handler.closeElement("IsMotorMount", attributes, "foo", warnings);
145 assertFalse(component.isMotorMount());
147 handler.closeElement("EngineOverhang", attributes, "-1", warnings);
148 assertEquals(-1d/RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
149 handler.closeElement("EngineOverhang", attributes, "10", warnings);
150 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
151 handler.closeElement("EngineOverhang", attributes, "10.0", warnings);
152 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getMotorOverhang());
153 handler.closeElement("EngineOverhang", attributes, "foo", warnings);
154 assertEquals(1, warnings.size());
157 handler.closeElement("FinishCode", attributes, "-1", warnings);
158 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
159 handler.closeElement("FinishCode", attributes, "100", warnings);
160 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
161 handler.closeElement("FinishCode", attributes, "foo", warnings);
162 assertEquals(1, warnings.size());
165 handler.closeElement("Name", attributes, "Test Name", warnings);
166 assertEquals("Test Name", component.getName());
170 * Method: getComponent()
172 * @throws Exception thrown if something goes awry
174 public void testGetComponent() throws Exception {
175 assertTrue(new BodyTubeHandler(new Stage(), new WarningSet()).getComponent() instanceof BodyTube);
179 * Method: getMaterialType()
181 * @throws Exception thrown if something goes awry
183 public void testGetMaterialType() throws Exception {
184 assertEquals(Material.Type.BULK, new BodyTubeHandler(new Stage(), new WarningSet()).getMaterialType());