Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
bc282a0e6c
@ -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<MotorConfiguration>(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<MotorConfiguration>(this, ComponentChangeEvent.MOTOR_CHANGE, MotorConfiguration.NO_MOTORS);
|
||||
this.ignitionConfigurations = new FlightConfigurationImpl<IgnitionConfiguration>(this, ComponentChangeEvent.EVENT_CHANGE, new IgnitionConfiguration());
|
||||
}
|
||||
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
32
core/test/net/sf/openrocket/BaseApplicationAbstractTest.java
Normal file
32
core/test/net/sf/openrocket/BaseApplicationAbstractTest.java
Normal file
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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<ThrustCurveMotorSetDatabase>() {
|
||||
|
||||
@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() {
|
||||
|
@ -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());
|
||||
|
@ -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<RocketComponent> components) {
|
||||
Assert.assertTrue("Components did not contain child", components.contains(child));
|
||||
}
|
||||
@ -92,5 +85,5 @@ public abstract class RocksimTestBase {
|
||||
cls.getName() + "." + name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<Double,Value>(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<Double, Value>(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<Double,Value>(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<Double, Value>(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<Double,Value>(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<Double, Value>(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<Double,Value>(ddist, dref)));
|
||||
}});
|
||||
oneOf(domain).getDistanceToDomain(simulation);
|
||||
will(returnValue(new Pair<Double, Value>(ddist, dref)));
|
||||
}
|
||||
});
|
||||
// @formatter:on
|
||||
|
||||
|
||||
|
||||
RocketOptimizationFunction function = new RocketOptimizationFunction(simulation,
|
||||
parameter, goal, domain, modifier1, modifier2) {
|
||||
@Override
|
||||
|
@ -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<TestValue> gm;
|
||||
|
@ -1,9 +1,14 @@
|
||||
package net.sf.openrocket.plugin;
|
||||
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.startup.ApplicationModule;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Module;
|
||||
|
||||
/**
|
||||
* Test the plugin loading system using Guice.
|
||||
@ -17,7 +22,11 @@ public class PluginTest {
|
||||
@Test
|
||||
public void testPluginModule() {
|
||||
|
||||
Injector injector = Guice.createInjector(new PluginModule());
|
||||
Application.setPreferences(new SwingPreferences());
|
||||
|
||||
Module applicationModule = new ApplicationModule();
|
||||
|
||||
Injector injector = Guice.createInjector(applicationModule, new PluginModule());
|
||||
PluginTester tester = injector.getInstance(PluginTester.class);
|
||||
tester.testPlugins();
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user