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.database.Databases;
10 import net.sf.openrocket.file.simplesax.PlainTextHandler;
11 import net.sf.openrocket.material.Material;
12 import net.sf.openrocket.rocketcomponent.BodyTube;
13 import net.sf.openrocket.rocketcomponent.ExternalComponent;
14 import net.sf.openrocket.rocketcomponent.LaunchLug;
15 import net.sf.openrocket.rocketcomponent.RocketComponent;
17 import java.util.HashMap;
20 * LaunchLugHandler Tester.
23 public class LaunchLugHandlerTest extends RocksimTestBase {
26 * The class under test.
28 public static final Class classUT = LaunchLugHandler.class;
31 * The test class (this class).
33 public static final Class testClass = LaunchLugHandlerTest.class;
36 * Create a test suite of all tests within this test class.
38 * @return a suite of tests
40 public static Test suite() {
41 return new TestSuite(LaunchLugHandlerTest.class);
47 * @param name the name of the test to run.
49 public LaunchLugHandlerTest(String name) {
56 public void setUp() throws Exception {
61 * Teardown the fixture.
63 public void tearDown() throws Exception {
70 * @throws Exception thrown if something goes awry
72 public void testConstructor() throws Exception {
75 new LaunchLugHandler(null);
76 fail("Should have thrown IllegalArgumentException");
78 catch (IllegalArgumentException iae) {
82 BodyTube tube = new BodyTube();
83 LaunchLugHandler handler = new LaunchLugHandler(tube);
84 LaunchLug component = (LaunchLug) getField(handler, "lug");
85 assertContains(component, tube.getChildren());
89 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
91 * @throws Exception thrown if something goes awry
93 public void testOpenElement() throws Exception {
94 assertEquals(PlainTextHandler.INSTANCE, new LaunchLugHandler(new BodyTube()).openElement(null, 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 BodyTube tube = new BodyTube();
105 LaunchLugHandler handler = new LaunchLugHandler(tube);
106 LaunchLug component = (LaunchLug) getField(handler, "lug");
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.getRadius());
112 handler.closeElement("OD", attributes, "0", warnings);
113 assertEquals(0d, component.getRadius());
114 handler.closeElement("OD", attributes, "75", warnings);
115 assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getRadius());
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("FinishCode", attributes, "-1", warnings);
141 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
142 handler.closeElement("FinishCode", attributes, "100", warnings);
143 assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
144 handler.closeElement("FinishCode", attributes, "foo", warnings);
145 assertEquals(1, warnings.size());
148 handler.closeElement("Name", attributes, "Test Name", warnings);
149 assertEquals("Test Name", component.getName());
153 * Method: setRelativePosition(RocketComponent.Position position)
155 * @throws Exception thrown if something goes awry
157 public void testSetRelativePosition() throws Exception {
158 BodyTube tube = new BodyTube();
159 LaunchLugHandler handler = new LaunchLugHandler(tube);
160 LaunchLug component = (LaunchLug) getField(handler, "lug");
161 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
162 assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
166 * Method: getComponent()
168 * @throws Exception thrown if something goes awry
170 public void testGetComponent() throws Exception {
171 assertTrue(new LaunchLugHandler(new BodyTube()).getComponent() instanceof LaunchLug);
175 * Method: getMaterialType()
177 * @throws Exception thrown if something goes awry
179 public void testGetMaterialType() throws Exception {
180 assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube()).getMaterialType());