2 * LaunchLugHandlerTest.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.LaunchLug;
14 import net.sf.openrocket.rocketcomponent.RocketComponent;
16 import java.util.HashMap;
19 * LaunchLugHandler Tester.
22 public class LaunchLugHandlerTest extends RocksimTestBase {
25 * The class under test.
27 public static final Class classUT = LaunchLugHandler.class;
30 * The test class (this class).
32 public static final Class testClass = LaunchLugHandlerTest.class;
35 * Create a test suite of all tests within this test class.
37 * @return a suite of tests
39 public static Test suite() {
40 return new TestSuite(LaunchLugHandlerTest.class);
46 * @param name the name of the test to run.
48 public LaunchLugHandlerTest(String name) {
55 public void setUp() throws Exception {
60 * Teardown the fixture.
62 public void tearDown() throws Exception {
69 * @throws Exception thrown if something goes awry
71 public void testConstructor() throws Exception {
74 new LaunchLugHandler(null, new WarningSet());
75 fail("Should have thrown IllegalArgumentException");
77 catch (IllegalArgumentException iae) {
81 BodyTube tube = new BodyTube();
82 LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
83 LaunchLug component = (LaunchLug) getField(handler, "lug");
84 assertContains(component, tube.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 LaunchLugHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
98 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
100 * @throws Exception thrown if something goes awry
102 public void testCloseElement() throws Exception {
103 BodyTube tube = new BodyTube();
104 LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
105 LaunchLug component = (LaunchLug) getField(handler, "lug");
106 HashMap<String, String> attributes = new HashMap<String, String>();
107 WarningSet warnings = new WarningSet();
109 handler.closeElement("OD", attributes, "-1", warnings);
110 assertEquals(0d, component.getRadius());
111 handler.closeElement("OD", attributes, "0", warnings);
112 assertEquals(0d, component.getRadius());
113 handler.closeElement("OD", attributes, "75", warnings);
114 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getRadius());
115 handler.closeElement("OD", attributes, "foo", warnings);
116 assertEquals(1, warnings.size());
119 handler.closeElement("ID", attributes, "-1", warnings);
120 assertEquals(0d, component.getInnerRadius());
121 handler.closeElement("ID", attributes, "0", warnings);
122 assertEquals(0d, component.getInnerRadius());
123 handler.closeElement("ID", attributes, "75", warnings);
124 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius());
125 handler.closeElement("ID", attributes, "foo", warnings);
126 assertEquals(1, warnings.size());
129 handler.closeElement("Len", attributes, "-1", warnings);
130 assertEquals(0d, component.getLength());
131 handler.closeElement("Len", attributes, "10", warnings);
132 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
133 handler.closeElement("Len", attributes, "10.0", warnings);
134 assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength());
135 handler.closeElement("Len", attributes, "foo", warnings);
136 assertEquals(1, warnings.size());
139 handler.closeElement("FinishCode", attributes, "-1", warnings);
140 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
141 handler.closeElement("FinishCode", attributes, "100", warnings);
142 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
143 handler.closeElement("FinishCode", attributes, "foo", warnings);
144 assertEquals(1, warnings.size());
147 handler.closeElement("Name", attributes, "Test Name", warnings);
148 assertEquals("Test Name", component.getName());
152 * Method: setRelativePosition(RocketComponent.Position position)
154 * @throws Exception thrown if something goes awry
156 public void testSetRelativePosition() throws Exception {
157 BodyTube tube = new BodyTube();
158 LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
159 LaunchLug component = (LaunchLug) getField(handler, "lug");
160 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
161 assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
165 * Method: getComponent()
167 * @throws Exception thrown if something goes awry
169 public void testGetComponent() throws Exception {
170 assertTrue(new LaunchLugHandler(new BodyTube(), new WarningSet()).getComponent() instanceof LaunchLug);
174 * Method: getMaterialType()
176 * @throws Exception thrown if something goes awry
178 public void testGetMaterialType() throws Exception {
179 assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube(), new WarningSet()).getMaterialType());