diff --git a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java index ccfc387f8..865835533 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java +++ b/core/src/net/sf/openrocket/rocketcomponent/BodyTube.java @@ -33,9 +33,7 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial public BodyTube() { - super(); - this.length = 8 * DEFAULT_RADIUS; - this.outerRadius = DEFAULT_RADIUS; + this(8 * DEFAULT_RADIUS, DEFAULT_RADIUS); this.autoRadius = true; this.motorConfigurations = new MotorFlightConfigurationImpl(this, ComponentChangeEvent.MOTOR_CHANGE, MotorConfiguration.NO_MOTORS); @@ -46,6 +44,8 @@ public class BodyTube extends SymmetricComponent implements MotorMount, Coaxial super(); this.outerRadius = Math.max(radius, 0); this.length = Math.max(length, 0); + this.motorConfigurations = new MotorFlightConfigurationImpl(this, ComponentChangeEvent.MOTOR_CHANGE, MotorConfiguration.NO_MOTORS); + this.ignitionConfigurations = new FlightConfigurationImpl(this, ComponentChangeEvent.EVENT_CHANGE, new IgnitionConfiguration()); } diff --git a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java index fd56b2821..0a09a7da7 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java +++ b/core/src/net/sf/openrocket/rocketcomponent/RocketComponent.java @@ -426,17 +426,20 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab */ public void setAppearance(Appearance appearance) { this.appearance = appearance; - Decal d = this.appearance.getTexture(); - if (d != null) { - d.getImage().addChangeListener(new StateChangeListener() { - - @Override - public void stateChanged(EventObject e) { - fireComponentChangeEvent(ComponentChangeEvent.TEXTURE_CHANGE); - } - - }); + if (this.appearance != null) { + Decal d = this.appearance.getTexture(); + if (d != null) { + d.getImage().addChangeListener(new StateChangeListener() { + + @Override + public void stateChanged(EventObject e) { + fireComponentChangeEvent(ComponentChangeEvent.TEXTURE_CHANGE); + } + + }); + } } + // CHECK - should this be a TEXTURE_CHANGE and not NONFUNCTIONAL_CHANGE? fireComponentChangeEvent(ComponentChangeEvent.NONFUNCTIONAL_CHANGE); } diff --git a/core/test/net/sf/openrocket/BaseApplicationAbstractTest.java b/core/test/net/sf/openrocket/BaseApplicationAbstractTest.java new file mode 100644 index 000000000..547842042 --- /dev/null +++ b/core/test/net/sf/openrocket/BaseApplicationAbstractTest.java @@ -0,0 +1,32 @@ +package net.sf.openrocket; + +import net.sf.openrocket.gui.util.SwingPreferences; +import net.sf.openrocket.plugin.PluginModule; +import net.sf.openrocket.startup.Application; +import net.sf.openrocket.startup.ApplicationModule; + +import org.junit.BeforeClass; + +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Module; + + +public abstract class BaseApplicationAbstractTest { + + + @BeforeClass + public static void setUp() throws Exception { + Application.setInjector(initializeGuice()); + } + + private static Injector initializeGuice() { + Application.setPreferences(new SwingPreferences()); + + Module applicationModule = new ApplicationModule(); + Module pluginModule = new PluginModule(); + + return Guice.createInjector(applicationModule, pluginModule); + } + +} diff --git a/core/test/net/sf/openrocket/IntegrationTest.java b/core/test/net/sf/openrocket/IntegrationTest.java index 599257017..4fbb754b0 100644 --- a/core/test/net/sf/openrocket/IntegrationTest.java +++ b/core/test/net/sf/openrocket/IntegrationTest.java @@ -16,7 +16,6 @@ import javax.swing.Action; import net.sf.openrocket.aerodynamics.AerodynamicCalculator; import net.sf.openrocket.aerodynamics.BarrowmanCalculator; import net.sf.openrocket.aerodynamics.FlightConditions; -import net.sf.openrocket.database.motor.MotorDatabase; import net.sf.openrocket.database.motor.ThrustCurveMotorSetDatabase; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.Simulation; @@ -38,32 +37,27 @@ import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.simulation.FlightDataType; import net.sf.openrocket.simulation.exception.SimulationException; import net.sf.openrocket.startup.Application; +import net.sf.openrocket.startup.ApplicationModule2; import net.sf.openrocket.util.Coordinate; -import net.sf.openrocket.util.BaseTestCase.BaseTestCase; -import org.jmock.Expectations; import org.jmock.Mockery; -import org.jmock.auto.Mock; import org.jmock.integration.junit4.JMock; import org.jmock.integration.junit4.JUnit4Mockery; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import com.google.inject.Injector; +import com.google.inject.Provider; /** * This class contains various integration tests that simulate user actions that * might be performed. */ @RunWith(JMock.class) -public class IntegrationTest extends BaseTestCase { +public class IntegrationTest extends BaseApplicationAbstractTest { Mockery context = new JUnit4Mockery(); - @Mock - Injector injector; - - private OpenRocketDocument document; private Action undoAction, redoAction; @@ -72,22 +66,27 @@ public class IntegrationTest extends BaseTestCase { private Configuration config; private FlightConditions conditions; - - @Before - public void initialize() { + @BeforeClass + public static void setupMotorDatabase() { + final ThrustCurveMotorSetDatabase db = new ThrustCurveMotorSetDatabase(); db.addMotor(readMotor()); - context.checking(new Expectations() { - { - allowing(injector).getInstance(MotorDatabase.class); - will(returnValue(db)); - } - }); - assertEquals(1, db.getMotorSets().size()); - Application.setInjector(injector); + + ApplicationModule2 module = new ApplicationModule2(new Provider() { + + @Override + public ThrustCurveMotorSetDatabase get() { + return db; + } + + }); + Injector injector2 = Application.getInjector().createChildInjector(module); + Application.setInjector(injector2); Application.setBaseTranslator(new ResourceBundleTranslator("l10n.messages")); + + } private static ThrustCurveMotor readMotor() { diff --git a/core/test/net/sf/openrocket/file/rocksim/importt/RocksimLoaderTest.java b/core/test/net/sf/openrocket/file/rocksim/importt/RocksimLoaderTest.java index 64c358cca..c65efc709 100644 --- a/core/test/net/sf/openrocket/file/rocksim/importt/RocksimLoaderTest.java +++ b/core/test/net/sf/openrocket/file/rocksim/importt/RocksimLoaderTest.java @@ -8,6 +8,7 @@ import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; +import net.sf.openrocket.BaseApplicationAbstractTest; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocumentFactory; import net.sf.openrocket.file.DatabaseMotorFinder; @@ -23,7 +24,7 @@ import org.junit.Assert; /** * RocksimLoader Tester. */ -public class RocksimLoaderTest { +public class RocksimLoaderTest extends BaseApplicationAbstractTest { /** * Test a bug reported via automated bug report. I have been unable to reproduce this bug @@ -83,7 +84,7 @@ public class RocksimLoaderTest { //Do some simple asserts; the important thing here is just validating that the mass and cg were //not overridden for each stage. Assert.assertEquals("Three Stage Everything Included Rocket", doc.getRocket().getName()); - Assert.assertEquals(1, loader.getWarnings().size()); + Assert.assertEquals(0, loader.getWarnings().size()); Assert.assertEquals(3, rocket.getStageCount()); Stage stage1 = (Stage) rocket.getChild(0); Assert.assertFalse(stage1.isMassOverridden()); diff --git a/core/test/net/sf/openrocket/file/rocksim/importt/RocksimTestBase.java b/core/test/net/sf/openrocket/file/rocksim/importt/RocksimTestBase.java index beb45c18a..f9f76e3df 100644 --- a/core/test/net/sf/openrocket/file/rocksim/importt/RocksimTestBase.java +++ b/core/test/net/sf/openrocket/file/rocksim/importt/RocksimTestBase.java @@ -3,29 +3,22 @@ */ package net.sf.openrocket.file.rocksim.importt; +import java.lang.reflect.Field; +import java.util.List; + +import net.sf.openrocket.BaseApplicationAbstractTest; import net.sf.openrocket.gui.util.SwingPreferences; import net.sf.openrocket.rocketcomponent.RocketComponent; import net.sf.openrocket.startup.Application; + import org.junit.Assert; import org.junit.Before; -import java.lang.reflect.Field; -import java.util.List; - /** * A base class for the Rocksim tests. Includes code from the junitx.addons project. */ -public abstract class RocksimTestBase { +public abstract class RocksimTestBase extends BaseApplicationAbstractTest { - /* (non-Javadoc) - * @see junit.framework.TestCase#setUp() - */ - @Before - public void setUp() throws Exception { - Application.setPreferences( new SwingPreferences() ); - } - - public void assertContains(RocketComponent child, List components) { Assert.assertTrue("Components did not contain child", components.contains(child)); } @@ -92,5 +85,5 @@ public abstract class RocksimTestBase { cls.getName() + "." + name); } - + } diff --git a/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java b/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java index 54267274e..3582a1c22 100644 --- a/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java +++ b/core/test/net/sf/openrocket/optimization/rocketoptimization/TestRocketOptimizationFunction.java @@ -1,6 +1,9 @@ package net.sf.openrocket.optimization.rocketoptimization; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import net.sf.openrocket.BaseApplicationAbstractTest; import net.sf.openrocket.document.Simulation; import net.sf.openrocket.optimization.general.OptimizationException; import net.sf.openrocket.optimization.general.Point; @@ -20,7 +23,7 @@ import org.junit.runner.RunWith; @RunWith(JMock.class) -public class TestRocketOptimizationFunction { +public class TestRocketOptimizationFunction extends BaseApplicationAbstractTest { Mockery context = new JUnit4Mockery(); @Mock @@ -51,22 +54,32 @@ public class TestRocketOptimizationFunction { final Point point = new Point(p1, p2); // @formatter:off - context.checking(new Expectations() {{ + context.checking(new Expectations() { + { oneOf(modifier1).modify(simulation, p1); oneOf(modifier2).modify(simulation, p2); - oneOf(domain).getDistanceToDomain(simulation); will(returnValue(new Pair(ddist, dref))); - oneOf(parameter).computeValue(simulation); will(returnValue(pvalue)); - oneOf(parameter).getUnitGroup(); will(returnValue(UnitGroup.UNITS_NONE)); - oneOf(goal).getMinimizationParameter(pvalue); will(returnValue(gvalue)); - oneOf(modifier1).getCurrentSIValue(simulation); will(returnValue(0.2)); - oneOf(modifier1).getUnitGroup(); will(returnValue(UnitGroup.UNITS_LENGTH)); - oneOf(modifier2).getCurrentSIValue(simulation); will(returnValue(0.3)); - oneOf(modifier2).getUnitGroup(); will(returnValue(UnitGroup.UNITS_LENGTH)); + oneOf(domain).getDistanceToDomain(simulation); + will(returnValue(new Pair(ddist, dref))); + oneOf(parameter).computeValue(simulation); + will(returnValue(pvalue)); + oneOf(parameter).getUnitGroup(); + will(returnValue(UnitGroup.UNITS_NONE)); + oneOf(goal).getMinimizationParameter(pvalue); + will(returnValue(gvalue)); + oneOf(modifier1).getCurrentSIValue(simulation); + will(returnValue(0.2)); + oneOf(modifier1).getUnitGroup(); + will(returnValue(UnitGroup.UNITS_LENGTH)); + oneOf(modifier2).getCurrentSIValue(simulation); + will(returnValue(0.3)); + oneOf(modifier2).getUnitGroup(); + will(returnValue(UnitGroup.UNITS_LENGTH)); oneOf(listener).evaluated(point, new Value[] { new Value(0.2, UnitGroup.UNITS_LENGTH.getDefaultUnit()), new Value(0.3, UnitGroup.UNITS_LENGTH.getDefaultUnit()) }, dref, pvalueValue, gvalue); - }}); + } + }); // @formatter:on RocketOptimizationFunction function = new RocketOptimizationFunction(simulation, @@ -94,17 +107,23 @@ public class TestRocketOptimizationFunction { final double pvalue = 9.81; // @formatter:off - context.checking(new Expectations() {{ + context.checking(new Expectations() { + { oneOf(modifier1).modify(simulation, p1); oneOf(modifier2).modify(simulation, p2); - oneOf(domain).getDistanceToDomain(simulation); will(returnValue(new Pair(ddist, dref))); - oneOf(parameter).computeValue(simulation); will(returnValue(pvalue)); - oneOf(parameter).getUnitGroup(); will(returnValue(UnitGroup.UNITS_NONE)); - oneOf(goal).getMinimizationParameter(pvalue); will(returnValue(Double.NaN)); - }}); + oneOf(domain).getDistanceToDomain(simulation); + will(returnValue(new Pair(ddist, dref))); + oneOf(parameter).computeValue(simulation); + will(returnValue(pvalue)); + oneOf(parameter).getUnitGroup(); + will(returnValue(UnitGroup.UNITS_NONE)); + oneOf(goal).getMinimizationParameter(pvalue); + will(returnValue(Double.NaN)); + } + }); // @formatter:on - + RocketOptimizationFunction function = new RocketOptimizationFunction(simulation, parameter, goal, domain, modifier1, modifier2) { @Override @@ -113,7 +132,7 @@ public class TestRocketOptimizationFunction { } }; - + double value = function.evaluate(new Point(p1, p2)); assertEquals(Double.MAX_VALUE, value, 0); } @@ -131,22 +150,29 @@ public class TestRocketOptimizationFunction { final Point point = new Point(p1, p2); // @formatter:off - context.checking(new Expectations() {{ + context.checking(new Expectations() { + { oneOf(modifier1).modify(simulation, p1); oneOf(modifier2).modify(simulation, p2); - oneOf(domain).getDistanceToDomain(simulation); will(returnValue(new Pair(ddist, dref))); - oneOf(modifier1).getCurrentSIValue(simulation); will(returnValue(0.2)); - oneOf(modifier1).getUnitGroup(); will(returnValue(UnitGroup.UNITS_LENGTH)); - oneOf(modifier2).getCurrentSIValue(simulation); will(returnValue(0.3)); - oneOf(modifier2).getUnitGroup(); will(returnValue(UnitGroup.UNITS_LENGTH)); + oneOf(domain).getDistanceToDomain(simulation); + will(returnValue(new Pair(ddist, dref))); + oneOf(modifier1).getCurrentSIValue(simulation); + will(returnValue(0.2)); + oneOf(modifier1).getUnitGroup(); + will(returnValue(UnitGroup.UNITS_LENGTH)); + oneOf(modifier2).getCurrentSIValue(simulation); + will(returnValue(0.3)); + oneOf(modifier2).getUnitGroup(); + will(returnValue(UnitGroup.UNITS_LENGTH)); oneOf(listener).evaluated(point, new Value[] { new Value(0.2, UnitGroup.UNITS_LENGTH.getDefaultUnit()), new Value(0.3, UnitGroup.UNITS_LENGTH.getDefaultUnit()) }, dref, null, 1.98E200); - }}); + } + }); // @formatter:on - + RocketOptimizationFunction function = new RocketOptimizationFunction(simulation, parameter, goal, domain, modifier1, modifier2) { @Override @@ -171,14 +197,17 @@ public class TestRocketOptimizationFunction { final Value dref = new Value(0.33, Unit.NOUNIT); // @formatter:off - context.checking(new Expectations() {{ + context.checking(new Expectations() { + { oneOf(modifier1).modify(simulation, p1); oneOf(modifier2).modify(simulation, p2); - oneOf(domain).getDistanceToDomain(simulation); will(returnValue(new Pair(ddist, dref))); - }}); + oneOf(domain).getDistanceToDomain(simulation); + will(returnValue(new Pair(ddist, dref))); + } + }); // @formatter:on - + RocketOptimizationFunction function = new RocketOptimizationFunction(simulation, parameter, goal, domain, modifier1, modifier2) { @Override diff --git a/core/test/net/sf/openrocket/optimization/rocketoptimization/modifiers/TestGenericModifier.java b/core/test/net/sf/openrocket/optimization/rocketoptimization/modifiers/TestGenericModifier.java index deacacf45..a36fc9262 100644 --- a/core/test/net/sf/openrocket/optimization/rocketoptimization/modifiers/TestGenericModifier.java +++ b/core/test/net/sf/openrocket/optimization/rocketoptimization/modifiers/TestGenericModifier.java @@ -2,6 +2,7 @@ package net.sf.openrocket.optimization.rocketoptimization.modifiers; import static net.sf.openrocket.util.MathUtil.EPSILON; import static org.junit.Assert.assertEquals; +import net.sf.openrocket.BaseApplicationAbstractTest; import net.sf.openrocket.document.Simulation; import net.sf.openrocket.optimization.general.OptimizationException; import net.sf.openrocket.rocketcomponent.Rocket; @@ -11,7 +12,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -public class TestGenericModifier { +public class TestGenericModifier extends BaseApplicationAbstractTest { private TestValue value; private GenericModifier gm; diff --git a/core/test/net/sf/openrocket/rocketcomponent/ComponentCompare.java b/core/test/net/sf/openrocket/rocketcomponent/ComponentCompare.java index f37d71d6c..8aff7b8e6 100644 --- a/core/test/net/sf/openrocket/rocketcomponent/ComponentCompare.java +++ b/core/test/net/sf/openrocket/rocketcomponent/ComponentCompare.java @@ -18,7 +18,10 @@ public class ComponentCompare { private static final String[] IGNORED_METHODS = { "getClass", "getChildCount", "getChildren", "getNextComponent", "getID", "getPreviousComponent", "getParent", "getRocket", "getRoot", "getStage", - "getStageNumber", "getComponentName", "getDefaultFlightConfiguration", + "getStageNumber", "getComponentName", + "getStageSeparationConfiguration", + "getMotorConfiguration", + "getIgnitionConfiguration", // Rocket specific methods: "getModID", "getMassModID", "getAerodynamicModID", "getTreeModID", "getFunctionalModID", "getFlightConfigurationIDs", "getDefaultConfiguration", "getMotorMounts" diff --git a/core/test/net/sf/openrocket/simulation/customexpression/TestExpressions.java b/core/test/net/sf/openrocket/simulation/customexpression/TestExpressions.java index 9df240497..594142aa0 100644 --- a/core/test/net/sf/openrocket/simulation/customexpression/TestExpressions.java +++ b/core/test/net/sf/openrocket/simulation/customexpression/TestExpressions.java @@ -1,11 +1,12 @@ package net.sf.openrocket.simulation.customexpression; +import net.sf.openrocket.BaseApplicationAbstractTest; import net.sf.openrocket.document.OpenRocketDocument; import net.sf.openrocket.document.OpenRocketDocumentFactory; import org.junit.Test; -public class TestExpressions { +public class TestExpressions extends BaseApplicationAbstractTest { @Test public void testExpressions() {