2 * MassObjectHandlerTest.java
4 package net.sf.openrocket.file.rocksim;
6 import junit.framework.Test;
7 import junit.framework.TestSuite;
8 import net.sf.openrocket.file.simplesax.PlainTextHandler;
9 import net.sf.openrocket.material.Material;
10 import net.sf.openrocket.rocketcomponent.BodyTube;
11 import net.sf.openrocket.rocketcomponent.MassComponent;
12 import net.sf.openrocket.rocketcomponent.RocketComponent;
13 import net.sf.openrocket.rocketcomponent.Stage;
14 import net.sf.openrocket.rocketcomponent.NoseCone;
15 import net.sf.openrocket.rocketcomponent.Transition;
16 import net.sf.openrocket.aerodynamics.WarningSet;
18 import java.util.HashMap;
21 * MassObjectHandler Tester.
24 public class MassObjectHandlerTest extends RocksimTestBase {
27 * The class under test.
29 public static final Class classUT = MassObjectHandler.class;
32 * The test class (this class).
34 public static final Class testClass = MassObjectHandlerTest.class;
37 * Create a test suite of all tests within this test class.
39 * @return a suite of tests
41 public static Test suite() {
42 return new TestSuite(MassObjectHandlerTest.class);
48 * @param name the name of the test to run.
50 public MassObjectHandlerTest(String name) {
57 public void setUp() throws Exception {
62 * Teardown the fixture.
64 public void tearDown() throws Exception {
71 * @throws Exception thrown if something goes awry
73 public void testConstructor() throws Exception {
76 new MassObjectHandler(null);
77 fail("Should have thrown IllegalArgumentException");
79 catch (IllegalArgumentException iae) {
83 BodyTube tube = new BodyTube();
84 MassObjectHandler handler = new MassObjectHandler(tube);
85 MassComponent component = (MassComponent) getField(handler, "mass");
86 assertContains(component, tube.getChildren());
90 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
92 * @throws Exception thrown if something goes awry
94 public void testOpenElement() throws Exception {
95 assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(new BodyTube()).openElement(null, null, null));
100 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
102 * @throws Exception thrown if something goes awry
104 public void testCloseElement() throws Exception {
105 BodyTube tube = new BodyTube();
106 HashMap<String, String> attributes = new HashMap<String, String>();
107 WarningSet warnings = new WarningSet();
109 MassObjectHandler handler = new MassObjectHandler(tube);
110 MassComponent component = (MassComponent) getField(handler, "mass");
112 handler.closeElement("Len", attributes, "-1", warnings);
113 assertEquals(0d, component.getLength());
114 handler.closeElement("Len", attributes, "10", warnings);
115 assertEquals(10d / (MassObjectHandler.MASS_LEN_FUDGE_FACTOR * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH)
116 , component.getLength());
117 handler.closeElement("Len", attributes, "10.0", warnings);
118 assertEquals(10d / (MassObjectHandler.MASS_LEN_FUDGE_FACTOR * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH)
119 , component.getLength());
120 handler.closeElement("Len", attributes, "foo", warnings);
121 assertEquals(1, warnings.size());
124 handler.closeElement("KnownMass", attributes, "-1", warnings);
125 assertEquals(0d, component.getComponentMass());
126 handler.closeElement("KnownMass", attributes, "100", warnings);
127 assertEquals(100d / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS, component.getComponentMass());
128 handler.closeElement("KnownMass", attributes, "foo", warnings);
129 assertEquals(1, warnings.size());
135 * Method: setRelativePosition(RocketComponent.Position position)
137 * @throws Exception thrown if something goes awry
139 public void testSetRelativePosition() throws Exception {
140 BodyTube tube = new BodyTube();
141 MassObjectHandler handler = new MassObjectHandler(tube);
142 MassComponent component = (MassComponent) getField(handler, "mass");
143 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
144 assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
148 * Method: getComponent()
150 * @throws Exception thrown if something goes awry
152 public void testGetComponent() throws Exception {
153 assertTrue(new MassObjectHandler(new BodyTube()).getComponent() instanceof MassComponent);
157 * Method: getMaterialType()
159 * @throws Exception thrown if something goes awry
161 public void testGetMaterialType() throws Exception {
162 assertEquals(Material.Type.BULK, new MassObjectHandler(new BodyTube()).getMaterialType());