2 * MassObjectHandlerTest.java
4 package net.sf.openrocket.file.rocksim.importt;
6 import net.sf.openrocket.aerodynamics.WarningSet;
7 import net.sf.openrocket.file.rocksim.RocksimCommonConstants;
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 org.junit.Assert;
15 import java.util.HashMap;
18 * MassObjectHandler Tester.
21 public class MassObjectHandlerTest extends RocksimTestBase {
26 * @throws Exception thrown if something goes awry
29 public void testConstructor() throws Exception {
32 new MassObjectHandler(null, new WarningSet());
33 Assert.fail("Should have thrown IllegalArgumentException");
35 catch (IllegalArgumentException iae) {
39 BodyTube tube = new BodyTube();
40 MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
41 MassComponent mass = (MassComponent) getField(handler, "mass");
42 MassComponent current = (MassComponent) getField(handler, "current");
43 Assert.assertEquals(mass, current);
47 * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
49 * @throws Exception thrown if something goes awry
52 public void testOpenElement() throws Exception {
53 Assert.assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
58 * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
60 * @throws Exception thrown if something goes awry
63 public void testCloseElement() throws Exception {
64 BodyTube tube = new BodyTube();
65 HashMap<String, String> attributes = new HashMap<String, String>();
66 WarningSet warnings = new WarningSet();
68 MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
69 MassComponent component = (MassComponent) getField(handler, "mass");
71 handler.closeElement("Len", attributes, "-1", warnings);
72 Assert.assertEquals(0d, component.getLength(), 0.001);
73 handler.closeElement("Len", attributes, "10", warnings);
74 Assert.assertEquals(0.01
75 , component.getLength(), 0.001);
76 handler.closeElement("Len", attributes, "10.0", warnings);
77 Assert.assertEquals(0.01
78 , component.getLength(), 0.001);
79 handler.closeElement("Len", attributes, "foo", warnings);
80 Assert.assertEquals(1, warnings.size());
83 handler.closeElement("KnownMass", attributes, "-1", warnings);
84 Assert.assertEquals(0d, component.getComponentMass(), 0.001);
85 handler.closeElement("KnownMass", attributes, "100", warnings);
86 Assert.assertEquals(100d / RocksimCommonConstants.ROCKSIM_TO_OPENROCKET_MASS, component.getComponentMass(), 0.001);
87 handler.closeElement("KnownMass", attributes, "foo", warnings);
88 Assert.assertEquals(1, warnings.size());
94 * Method: setRelativePosition(RocketComponent.Position position)
96 * @throws Exception thrown if something goes awry
99 public void testSetRelativePosition() throws Exception {
100 BodyTube tube = new BodyTube();
101 MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
102 MassComponent component = (MassComponent) getField(handler, "mass");
103 handler.setRelativePosition(RocketComponent.Position.ABSOLUTE);
104 Assert.assertEquals(RocketComponent.Position.ABSOLUTE, component.getRelativePosition());
108 * Method: getComponent()
110 * @throws Exception thrown if something goes awry
113 public void testGetComponent() throws Exception {
114 Assert.assertTrue(new MassObjectHandler(new BodyTube(), new WarningSet()).getComponent() instanceof MassComponent);
118 * Method: getMaterialType()
120 * @throws Exception thrown if something goes awry
123 public void testGetMaterialType() throws Exception {
124 Assert.assertEquals(Material.Type.LINE, new MassObjectHandler(new BodyTube(), new WarningSet()).getMaterialType());