1 package net.sf.openrocket.rocketcomponent;
3 import static org.junit.Assert.*;
7 import net.sf.openrocket.material.Material;
8 import net.sf.openrocket.material.Material.Type;
9 import net.sf.openrocket.rocketcomponent.ExternalComponent.Finish;
10 import net.sf.openrocket.rocketcomponent.FinSet.CrossSection;
11 import net.sf.openrocket.rocketcomponent.FinSet.TabRelativePosition;
12 import net.sf.openrocket.rocketcomponent.RocketComponent.Position;
13 import net.sf.openrocket.util.LineStyle;
15 import org.junit.Test;
17 public class FinSetTest {
21 public void testFreeformConvert() {
22 testFreeformConvert(new TrapezoidFinSet());
23 testFreeformConvert(new EllipticalFinSet());
24 testFreeformConvert(new FreeformFinSet());
28 private void testFreeformConvert(FinSet fin) {
29 FreeformFinSet converted;
30 Material mat = Material.newMaterial(Type.BULK, "foo", 0.1, true);
32 fin.setBaseRotation(1.1);
33 fin.setCantAngle(0.001);
34 fin.setCGOverridden(true);
35 fin.setColor(Color.YELLOW);
36 fin.setComment("cmt");
37 fin.setCrossSection(CrossSection.ROUNDED);
39 fin.setFinish(Finish.ROUGH);
40 fin.setLineStyle(LineStyle.DASHDOT);
41 fin.setMassOverridden(true);
43 fin.setOverrideCGX(0.012);
44 fin.setOverrideMass(0.0123);
45 fin.setOverrideSubcomponents(true);
46 fin.setPositionValue(0.1);
47 fin.setRelativePosition(Position.ABSOLUTE);
48 fin.setTabHeight(0.01);
49 fin.setTabLength(0.02);
50 fin.setTabRelativePosition(TabRelativePosition.END);
51 fin.setTabShift(0.015);
52 fin.setThickness(0.005);
54 converted = FreeformFinSet.convertFinSet(fin);
56 ComponentCompare.assertSimilarity(fin, converted, true);
58 assertEquals(converted.getComponentName(), converted.getName());
62 Rocket rocket = new Rocket();
63 Stage stage = new Stage();
64 BodyTube body = new BodyTube();
66 rocket.addChild(stage);
70 Listener l1 = new Listener("l1");
71 rocket.addComponentChangeListener(l1);
73 fin.setName("Custom name");
74 assertTrue(l1.changed);
75 assertEquals(ComponentChangeEvent.NONFUNCTIONAL_CHANGE, l1.changetype);
79 RocketComponent rocketcopy = rocket.copy();
81 Listener l2 = new Listener("l2");
82 rocketcopy.addComponentChangeListener(l2);
84 FinSet fincopy = (FinSet) rocketcopy.getChild(0).getChild(0).getChild(0);
85 FreeformFinSet.convertFinSet(fincopy);
87 assertTrue(l2.changed);
88 assertEquals(ComponentChangeEvent.TREE_CHANGE,
89 l2.changetype & ComponentChangeEvent.TREE_CHANGE);
94 private static class Listener implements ComponentChangeListener {
95 private boolean changed = false;
96 private int changetype = 0;
97 private final String name;
99 public Listener(String name) {
104 public void componentChanged(ComponentChangeEvent e) {
105 assertFalse("Ensuring listener "+name+" has not been called.", changed);
107 changetype = e.getType();