2 * MassObjectHandlerTest.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.MassComponent;
11 import net.sf.openrocket.rocketcomponent.RocketComponent;
12 import org.junit.Assert;
14 import java.util.HashMap;
17 * MassObjectHandler Tester.
20 public class MassObjectHandlerTest extends RocksimTestBase {
25 * @throws Exception thrown if something goes awry
28 public void testConstructor() throws Exception {
31 new MassObjectHandler(null, new WarningSet());
32 Assert.fail("Should have thrown IllegalArgumentException");
34 catch (IllegalArgumentException iae) {
38 BodyTube tube = new BodyTube();
39 MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
40 MassComponent component = (MassComponent) getField(handler, "mass");
41 assertContains(component, tube.getChildren());
45 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
47 * @throws Exception thrown if something goes awry
50 public void testOpenElement() throws Exception {
51 Assert.assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
56 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
58 * @throws Exception thrown if something goes awry
61 public void testCloseElement() throws Exception {
62 BodyTube tube = new BodyTube();
63 HashMap<String, String> attributes = new HashMap<String, String>();
64 WarningSet warnings = new WarningSet();
66 MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
67 MassComponent component = (MassComponent) getField(handler, "mass");
69 handler.closeElement("Len", attributes, "-1", warnings);
70 Assert.assertEquals(0d, component.getLength(), 0.001);
71 handler.closeElement("Len", attributes, "10", warnings);
72 Assert.assertEquals(10d / (MassObjectHandler.MASS_LEN_FUDGE_FACTOR * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH)
73 , component.getLength(), 0.001);
74 handler.closeElement("Len", attributes, "10.0", warnings);
75 Assert.assertEquals(10d / (MassObjectHandler.MASS_LEN_FUDGE_FACTOR * RocksimHandler.ROCKSIM_TO_OPENROCKET_LENGTH)
76 , component.getLength(), 0.001);
77 handler.closeElement("Len", attributes, "foo", warnings);
78 Assert.assertEquals(1, warnings.size());
81 handler.closeElement("KnownMass", attributes, "-1", warnings);
82 Assert.assertEquals(0d, component.getComponentMass(), 0.001);
83 handler.closeElement("KnownMass", attributes, "100", warnings);
84 Assert.assertEquals(100d / RocksimHandler.ROCKSIM_TO_OPENROCKET_MASS, component.getComponentMass(), 0.001);
85 handler.closeElement("KnownMass", attributes, "foo", warnings);
86 Assert.assertEquals(1, warnings.size());
92 * Method: setRelativePosition(RocketComponent.Position position)
94 * @throws Exception thrown if something goes awry
97 public void testSetRelativePosition() throws Exception {
98 BodyTube tube = new BodyTube();
99 MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
100 MassComponent component = (MassComponent) getField(handler, "mass");
101 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
102 Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
106 * Method: getComponent()
108 * @throws Exception thrown if something goes awry
111 public void testGetComponent() throws Exception {
112 Assert.assertTrue(new MassObjectHandler(new BodyTube(), new WarningSet()).getComponent() instanceof MassComponent);
116 * Method: getMaterialType()
118 * @throws Exception thrown if something goes awry
121 public void testGetMaterialType() throws Exception {
122 Assert.assertEquals(Material.Type.BULK, new MassObjectHandler(new BodyTube(), new WarningSet()).getMaterialType());