]> git.gag.com Git - debian/openrocket/blob - test/net/sf/openrocket/file/rocksim/MassObjectHandlerTest.java
DGP - Modified Rocksim import to discriminate between centering ring, tube coupler...
[debian/openrocket] / test / net / sf / openrocket / file / rocksim / MassObjectHandlerTest.java
1 /*
2  * MassObjectHandlerTest.java
3  */
4 package net.sf.openrocket.file.rocksim;
5
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;
13
14 import java.util.HashMap;
15
16 /**
17  * MassObjectHandler Tester.
18  *
19  */
20 public class MassObjectHandlerTest extends RocksimTestBase {
21
22     /**
23      * Method: constructor
24      *
25      * @throws Exception thrown if something goes awry
26      */
27     @org.junit.Test
28     public void testConstructor() throws Exception {
29
30         try {
31             new MassObjectHandler(null, new WarningSet());
32             Assert.fail("Should have thrown IllegalArgumentException");
33         }
34         catch (IllegalArgumentException iae) {
35             //success
36         }
37
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());
42     }
43
44     /**
45      * Method: openElement(String element, HashMap<String, String> attributes, WarningSet warnings)
46      *
47      * @throws Exception thrown if something goes awry
48      */
49     @org.junit.Test
50     public void testOpenElement() throws Exception {
51         Assert.assertEquals(PlainTextHandler.INSTANCE, new MassObjectHandler(new BodyTube(), new WarningSet()).openElement(null, null, null));
52     }
53
54     /**
55      *
56      * Method: closeElement(String element, HashMap<String, String> attributes, String content, WarningSet warnings)
57      *
58      * @throws Exception  thrown if something goes awry
59      */
60     @org.junit.Test
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();
65
66         MassObjectHandler handler = new MassObjectHandler(tube, new WarningSet());
67         MassComponent component = (MassComponent) getField(handler, "mass");
68
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());
79         warnings.clear();
80
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());
87         warnings.clear();
88
89     }
90     
91     /**
92      * Method: setRelativePosition(RocketComponent.Position position)
93      *
94      * @throws Exception thrown if something goes awry
95      */
96     @org.junit.Test
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());
103     }
104
105     /**
106      * Method: getComponent()
107      *
108      * @throws Exception thrown if something goes awry
109      */
110     @org.junit.Test
111     public void testGetComponent() throws Exception {
112         Assert.assertTrue(new MassObjectHandler(new BodyTube(), new WarningSet()).getComponent() instanceof MassComponent);
113     }
114
115     /**
116      * Method: getMaterialType()
117      *
118      * @throws Exception thrown if something goes awry
119      */
120     @org.junit.Test
121     public void testGetMaterialType() throws Exception {
122         Assert.assertEquals(Material.Type.BULK, new MassObjectHandler(new BodyTube(), new WarningSet()).getMaterialType());
123     }
124 }