2 * LaunchLugHandlerTest.java
4 package net.sf.openrocket.file.rocksim;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.simplesax.PlainTextHandler;
8 import net.sf.openrocket.material.Material;
9 import net.sf.openrocket.rocketcomponent.BodyTube;
10 import net.sf.openrocket.rocketcomponent.ExternalComponent;
11 import net.sf.openrocket.rocketcomponent.LaunchLug;
12 import net.sf.openrocket.rocketcomponent.RocketComponent;
13 import org.junit.Assert;
15 import java.util.HashMap;
18 * LaunchLugHandler Tester.
21 public class LaunchLugHandlerTest extends RocksimTestBase {
26 * @throws Exception thrown if something goes awry
29 public void testConstructor() throws Exception {
32 new LaunchLugHandler(null, new WarningSet());
33 Assert.fail("Should have thrown IllegalArgumentException");
35 catch (IllegalArgumentException iae) {
39 BodyTube tube = new BodyTube();
40 LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
41 LaunchLug component = (LaunchLug) getField(handler, "lug");
42 assertContains(component, tube.getChildren());
46 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
48 * @throws Exception thrown if something goes awry
51 public void testOpenElement() throws Exception {
52 Assert.assertEquals(PlainTextHandler.INSTANCE, new LaunchLugHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
57 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
59 * @throws Exception thrown if something goes awry
62 public void testCloseElement() throws Exception {
63 BodyTube tube = new BodyTube();
64 LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
65 LaunchLug component = (LaunchLug) getField(handler, "lug");
66 HashMap<String, String> attributes = new HashMap<String, String>();
67 WarningSet warnings = new WarningSet();
69 handler.closeElement("OD", attributes, "-1", warnings);
70 Assert.assertEquals(0d, component.getOuterRadius(), 0.001);
71 handler.closeElement("OD", attributes, "0", warnings);
72 Assert.assertEquals(0d, component.getOuterRadius(), 0.001);
73 handler.closeElement("OD", attributes, "75", warnings);
74 Assert.assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getOuterRadius(), 0.001);
75 handler.closeElement("OD", attributes, "foo", warnings);
76 Assert.assertEquals(1, warnings.size());
79 handler.closeElement("ID", attributes, "-1", warnings);
80 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
81 handler.closeElement("ID", attributes, "0", warnings);
82 Assert.assertEquals(0d, component.getInnerRadius(), 0.001);
83 handler.closeElement("ID", attributes, "75", warnings);
84 Assert.assertEquals(75d / RocksimHandler.ROCKSIM_TO_OPENROCKET_RADIUS, component.getInnerRadius(), 0.001);
85 handler.closeElement("ID", attributes, "foo", warnings);
86 Assert.assertEquals(1, warnings.size());
89 handler.closeElement("Len", attributes, "-1", warnings);
90 Assert.assertEquals(0d, component.getLength(), 0.001);
91 handler.closeElement("Len", attributes, "10", warnings);
92 Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
93 handler.closeElement("Len", attributes, "10.0", warnings);
94 Assert.assertEquals(10d / RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH, component.getLength(), 0.001);
95 handler.closeElement("Len", attributes, "foo", warnings);
96 Assert.assertEquals(1, warnings.size());
99 handler.closeElement("FinishCode", attributes, "-1", warnings);
100 Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
101 handler.closeElement("FinishCode", attributes, "100", warnings);
102 Assert.assertEquals(ExternalComponent.Finish.NORMAL, component.getFinish());
103 handler.closeElement("FinishCode", attributes, "foo", warnings);
104 Assert.assertEquals(1, warnings.size());
107 handler.closeElement("Name", attributes, "Test Name", warnings);
108 Assert.assertEquals("Test Name", component.getName());
112 * Method: setRelativePosition(RocketComponent.Position position)
114 * @throws Exception thrown if something goes awry
117 public void testSetRelativePosition() throws Exception {
118 BodyTube tube = new BodyTube();
119 LaunchLugHandler handler = new LaunchLugHandler(tube, new WarningSet());
120 LaunchLug component = (LaunchLug) getField(handler, "lug");
121 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
122 Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
126 * Method: getComponent()
128 * @throws Exception thrown if something goes awry
131 public void testGetComponent() throws Exception {
132 Assert.assertTrue(new LaunchLugHandler(new BodyTube(), new WarningSet()).getComponent() instanceof LaunchLug);
136 * Method: getMaterialType()
138 * @throws Exception thrown if something goes awry
141 public void testGetMaterialType() throws Exception {
142 Assert.assertEquals(Material.Type.BULK, new LaunchLugHandler(new BodyTube(), new WarningSet()).getMaterialType());