Change the InvalidComponentPresetException so it reports all errors found in a preset instead of just the first. Changed all the test cases to ensure the proper errors are reported.

This commit is contained in:
Kevin Ruland 2012-05-06 13:27:30 +00:00
parent a32bfe7366
commit 370dfd0e18
13 changed files with 662 additions and 119 deletions

View File

@ -10,19 +10,22 @@ public abstract class ComponentPresetFactory {
public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException { public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException {
InvalidComponentPresetException exceptions = new InvalidComponentPresetException("Invalid preset specification.");
ComponentPreset preset = new ComponentPreset(); ComponentPreset preset = new ComponentPreset();
// First do validation. // First do validation.
if ( !props.containsKey(TYPE)) {
throw new InvalidComponentPresetException("No Type specified " + props.toString() );
}
if (!props.containsKey(MANUFACTURER)) { if (!props.containsKey(MANUFACTURER)) {
throw new InvalidComponentPresetException("No Manufacturer specified " + props.toString() ); exceptions.addInvalidParameter(MANUFACTURER, "No Manufacturer specified");
}
if (!props.containsKey(PARTNO)) {
exceptions.addInvalidParameter(PARTNO,"No PartNo specified");
}
if ( !props.containsKey(TYPE)) {
exceptions.addInvalidParameter(TYPE, "No Type specified" );
// We can't do anything else without TYPE so throw immediately.
throw exceptions;
} }
if (!props.containsKey(PARTNO)) {
throw new InvalidComponentPresetException("No PartNo specified " + props.toString() );
}
preset.putAll(props); preset.putAll(props);
@ -30,60 +33,64 @@ public abstract class ComponentPresetFactory {
Type t = props.get(TYPE); Type t = props.get(TYPE);
switch ( t ) { switch ( t ) {
case BODY_TUBE: { case BODY_TUBE: {
makeBodyTube(preset); makeBodyTube(exceptions,preset);
break; break;
} }
case NOSE_CONE: { case NOSE_CONE: {
makeNoseCone(preset); makeNoseCone(exceptions,preset);
break; break;
} }
case TRANSITION: { case TRANSITION: {
makeTransition(preset); makeTransition(exceptions,preset);
break; break;
} }
case BULK_HEAD: { case BULK_HEAD: {
makeBulkHead(preset); makeBulkHead(exceptions,preset);
break; break;
} }
case TUBE_COUPLER: { case TUBE_COUPLER: {
// For now TUBE_COUPLER is the same as BODY_TUBE // For now TUBE_COUPLER is the same as BODY_TUBE
makeBodyTube(preset); makeBodyTube(exceptions,preset);
break; break;
} }
case CENTERING_RING: { case CENTERING_RING: {
makeCenteringRing(preset); makeCenteringRing(exceptions,preset);
break; break;
} }
case ENGINE_BLOCK: { case ENGINE_BLOCK: {
makeEngineBlock(preset); makeEngineBlock(exceptions,preset);
break; break;
} }
case LAUNCH_LUG: { case LAUNCH_LUG: {
// Same processing as BODY_TUBE // Same processing as BODY_TUBE
makeBodyTube(preset); makeBodyTube(exceptions,preset);
break; break;
} }
case STREAMER: { case STREAMER: {
makeStreamer(preset); makeStreamer(exceptions,preset);
break; break;
} }
case PARACHUTE: { case PARACHUTE: {
makeParachute(preset); makeParachute(exceptions,preset);
break; break;
} }
} }
if ( exceptions.hasProblems() ) {
throw exceptions;
}
preset.computeDigest(); preset.computeDigest();
return preset; return preset;
} }
private static void makeBodyTube( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeBodyTube( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
checkRequiredFields( preset, LENGTH ); checkRequiredFields( exceptions, preset, LENGTH );
checkDiametersAndThickness(preset); checkDiametersAndThickness(exceptions, preset);
double volume = computeVolumeOfTube( preset ); double volume = computeVolumeOfTube( preset );
@ -100,9 +107,9 @@ public abstract class ComponentPresetFactory {
} }
private static void makeNoseCone( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeNoseCone( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
checkRequiredFields( preset, LENGTH, SHAPE, AFT_OUTER_DIAMETER ); checkRequiredFields( exceptions, preset, LENGTH, SHAPE, AFT_OUTER_DIAMETER );
if ( preset.has(MASS) ) { if ( preset.has(MASS) ) {
// compute a density for this component // compute a density for this component
@ -123,8 +130,8 @@ public abstract class ComponentPresetFactory {
} }
private static void makeTransition( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeTransition( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
checkRequiredFields(preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER); checkRequiredFields(exceptions, preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER);
if ( preset.has(MASS) ) { if ( preset.has(MASS) ) {
// compute a density for this component // compute a density for this component
@ -145,8 +152,8 @@ public abstract class ComponentPresetFactory {
} }
private static void makeBulkHead( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeBulkHead( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
checkRequiredFields(preset, LENGTH, OUTER_DIAMETER ); checkRequiredFields(exceptions, preset, LENGTH, OUTER_DIAMETER );
if ( preset.has(MASS) ) { if ( preset.has(MASS) ) {
// compute a density for this component // compute a density for this component
@ -167,10 +174,10 @@ public abstract class ComponentPresetFactory {
} }
private static void makeCenteringRing( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeCenteringRing( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
checkRequiredFields( preset, LENGTH ); checkRequiredFields( exceptions, preset, LENGTH );
checkDiametersAndThickness( preset ); checkDiametersAndThickness( exceptions, preset );
double volume = computeVolumeOfTube( preset ); double volume = computeVolumeOfTube( preset );
@ -186,10 +193,10 @@ public abstract class ComponentPresetFactory {
} }
private static void makeEngineBlock( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeEngineBlock( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
checkRequiredFields( preset, LENGTH ); checkRequiredFields( exceptions, preset, LENGTH );
checkDiametersAndThickness( preset ); checkDiametersAndThickness( exceptions, preset );
double volume = computeVolumeOfTube( preset ); double volume = computeVolumeOfTube( preset );
@ -205,24 +212,24 @@ public abstract class ComponentPresetFactory {
} }
private static void makeStreamer( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeStreamer( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
checkRequiredFields( preset, LENGTH, WIDTH ); checkRequiredFields( exceptions, preset, LENGTH, WIDTH );
} }
private static void makeParachute( ComponentPreset preset ) throws InvalidComponentPresetException { private static void makeParachute( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
checkRequiredFields( preset, DIAMETER, LINE_COUNT, LINE_LENGTH ); checkRequiredFields( exceptions, preset, DIAMETER, LINE_COUNT, LINE_LENGTH );
} }
private static void checkRequiredFields( ComponentPreset preset, TypedKey<?> ... keys ) throws InvalidComponentPresetException { private static void checkRequiredFields( InvalidComponentPresetException exceptions, ComponentPreset preset, TypedKey<?> ... keys ) {
for( TypedKey<?> key: keys ) { for( TypedKey<?> key: keys ) {
if (! preset.has(key) ) { if (! preset.has(key) ) {
throw new InvalidComponentPresetException( "No " + key.getName() + " specified for " + preset.getType().name() + " preset " + preset.toString()); exceptions.addInvalidParameter(key, "No " + key.getName() + " specified");
} }
} }
} }
private static void checkDiametersAndThickness( ComponentPreset preset ) throws InvalidComponentPresetException { private static void checkDiametersAndThickness( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
// Need to verify contains 2 of OD, thickness, ID. Compute the third. // Need to verify contains 2 of OD, thickness, ID. Compute the third.
boolean hasOd = preset.has(OUTER_DIAMETER); boolean hasOd = preset.has(OUTER_DIAMETER);
boolean hasId = preset.has(INNER_DIAMETER); boolean hasId = preset.has(INNER_DIAMETER);
@ -242,11 +249,13 @@ public abstract class ComponentPresetFactory {
thickness = preset.get(THICKNESS); thickness = preset.get(THICKNESS);
innerRadius = outerRadius - thickness; innerRadius = outerRadius - thickness;
} else { } else {
throw new InvalidComponentPresetException("Preset underspecified " + preset.toString()); exceptions.addMessage("Preset dimensions underspecified");
throw exceptions;
} }
} else { } else {
if ( ! hasId || ! hasThickness ) { if ( ! hasId || ! hasThickness ) {
throw new InvalidComponentPresetException("Preset underspecified " + preset.toString()); exceptions.addMessage("Preset dimensions underspecified");
throw exceptions;
} }
innerRadius = preset.get(INNER_DIAMETER)/2.0; innerRadius = preset.get(INNER_DIAMETER)/2.0;
thickness = preset.get(THICKNESS); thickness = preset.get(THICKNESS);

View File

@ -1,25 +1,56 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import java.util.ArrayList;
import java.util.List;
public class InvalidComponentPresetException extends Exception { public class InvalidComponentPresetException extends Exception {
private List<String> errors = new ArrayList<String>();
private List<TypedKey<?>> invalidParameters = new ArrayList<TypedKey<?>>();
public InvalidComponentPresetException() { public InvalidComponentPresetException() {
super(); super();
// TODO Auto-generated constructor stub
} }
public InvalidComponentPresetException(String message, Throwable cause) { public InvalidComponentPresetException(String message, Throwable cause) {
super(message, cause); super(message, cause);
// TODO Auto-generated constructor stub
} }
public InvalidComponentPresetException(String message) { public InvalidComponentPresetException(String message) {
super(message); super(message);
// TODO Auto-generated constructor stub
} }
public InvalidComponentPresetException(Throwable cause) { public InvalidComponentPresetException(Throwable cause) {
super(cause); super(cause);
// TODO Auto-generated constructor stub }
void addInvalidParameter(TypedKey<?> key ) {
invalidParameters.add(key);
}
void addInvalidParameter(TypedKey<?> key, String message ) {
invalidParameters.add(key);
errors.add(message);
}
void addMessage( String message ) {
errors.add(message);
} }
boolean hasProblems() {
return (invalidParameters.size() + errors.size()) > 0;
}
public int problemCount() {
return Math.max( invalidParameters.size(), errors.size() );
}
public List<String> getErrors() {
return errors;
}
public List<TypedKey<?>> getInvalidParameters() {
return invalidParameters;
}
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -25,7 +24,19 @@ public class BodyTubePresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -37,7 +48,17 @@ public class BodyTubePresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -50,7 +71,15 @@ public class BodyTubePresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH
},
new String[] {
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -65,7 +94,12 @@ public class BodyTubePresetTests {
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -80,7 +114,12 @@ public class BodyTubePresetTests {
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -95,7 +134,12 @@ public class BodyTubePresetTests {
presetspec.put( ComponentPreset.THICKNESS, 2.0); presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -175,9 +219,9 @@ public class BodyTubePresetTests {
// constants put into the presetspec above. // constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */ volume *= 2.0; /* times length */
double density = 100.0 / volume; double density = 100.0 / volume;
assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName()); assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
} }
@ -196,7 +240,7 @@ public class BodyTubePresetTests {
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
} }
@Test @Test
@ -217,9 +261,9 @@ public class BodyTubePresetTests {
// constants put into the presetspec above. // constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */ volume *= 2.0; /* times length */
double density = 100.0 / volume; double density = 100.0 / volume;
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -25,7 +24,20 @@ public class BulkHeadPresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.OUTER_DIAMETER
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"No OuterDiameter specified"
}
);
} }
} }
@ -37,7 +49,18 @@ public class BulkHeadPresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.OUTER_DIAMETER
},
new String[] {
"No PartNo specified",
"No Length specified",
"No OuterDiameter specified"
}
);
} }
} }
@ -50,7 +73,16 @@ public class BulkHeadPresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH,
ComponentPreset.OUTER_DIAMETER
},
new String[] {
"No Length specified",
"No OuterDiameter specified"
}
);
} }
} }
@ -64,7 +96,14 @@ public class BulkHeadPresetTests {
presetspec.put( ComponentPreset.LENGTH, 2.0); presetspec.put( ComponentPreset.LENGTH, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No OuterDiameter specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.OUTER_DIAMETER
},
new String[] {
"No OuterDiameter specified"
}
);
} }
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -25,7 +24,19 @@ public class CenteringRingPresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -37,7 +48,17 @@ public class CenteringRingPresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -50,7 +71,15 @@ public class CenteringRingPresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH
},
new String[] {
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -65,7 +94,12 @@ public class CenteringRingPresetTests {
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -80,7 +114,12 @@ public class CenteringRingPresetTests {
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -95,7 +134,12 @@ public class CenteringRingPresetTests {
presetspec.put( ComponentPreset.THICKNESS, 2.0); presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -175,9 +219,9 @@ public class CenteringRingPresetTests {
// constants put into the presetspec above. // constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */ volume *= 2.0; /* times length */
double density = 100.0 / volume; double density = 100.0 / volume;
assertEquals("CenteringRingCustom",preset.get(ComponentPreset.MATERIAL).getName()); assertEquals("CenteringRingCustom",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
} }
@ -196,7 +240,7 @@ public class CenteringRingPresetTests {
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
} }
@Test @Test
@ -217,9 +261,9 @@ public class CenteringRingPresetTests {
// constants put into the presetspec above. // constants put into the presetspec above.
double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25); double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
volume *= 2.0; /* times length */ volume *= 2.0; /* times length */
double density = 100.0 / volume; double density = 100.0 / volume;
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName()); assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005); assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -25,7 +24,19 @@ public class EngineBlockPresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -37,7 +48,17 @@ public class EngineBlockPresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -50,7 +71,15 @@ public class EngineBlockPresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH
},
new String[] {
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -65,7 +94,12 @@ public class EngineBlockPresetTests {
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -80,7 +114,12 @@ public class EngineBlockPresetTests {
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -95,7 +134,12 @@ public class EngineBlockPresetTests {
presetspec.put( ComponentPreset.THICKNESS, 2.0); presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -25,7 +24,19 @@ public class LaunchLugPresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -37,7 +48,17 @@ public class LaunchLugPresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -50,7 +71,15 @@ public class LaunchLugPresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH
},
new String[] {
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -65,7 +94,12 @@ public class LaunchLugPresetTests {
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -80,7 +114,12 @@ public class LaunchLugPresetTests {
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -95,7 +134,12 @@ public class LaunchLugPresetTests {
presetspec.put( ComponentPreset.THICKNESS, 2.0); presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.Transition;
@ -27,7 +26,22 @@ public class NoseConePresetTests extends BaseTestCase {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.SHAPE
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"No AftOuterDiameter specified",
"No Shape specified"
}
);
} }
} }
@ -39,7 +53,20 @@ public class NoseConePresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.SHAPE
},
new String[] {
"No PartNo specified",
"No Length specified",
"No AftOuterDiameter specified",
"No Shape specified"
}
);
} }
} }
@ -52,7 +79,18 @@ public class NoseConePresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH,
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.SHAPE
},
new String[] {
"No Length specified",
"No AftOuterDiameter specified",
"No Shape specified"
}
);
} }
} }
@ -66,7 +104,16 @@ public class NoseConePresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.LENGTH, 2.0); presetspec.put( ComponentPreset.LENGTH, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Shape")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.SHAPE
},
new String[] {
"No AftOuterDiameter specified",
"No Shape specified"
}
);
} }
} }
@ -81,7 +128,14 @@ public class NoseConePresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.AFT_OUTER_DIAMETER
},
new String[] {
"No AftOuterDiameter specified"
}
);
} }
} }

View File

@ -1,6 +1,5 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
import org.junit.Test; import org.junit.Test;
@ -23,7 +22,22 @@ public class ParachutePresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.PARACHUTE); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.PARACHUTE);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.DIAMETER,
ComponentPreset.LINE_COUNT,
ComponentPreset.LINE_LENGTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Diameter specified",
"No LineCount specified",
"No LineLength specified"
}
);
} }
} }
@ -35,7 +49,20 @@ public class ParachutePresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.DIAMETER,
ComponentPreset.LINE_COUNT,
ComponentPreset.LINE_LENGTH
},
new String[] {
"No PartNo specified",
"No Diameter specified",
"No LineCount specified",
"No LineLength specified"
}
);
} }
} }
@ -48,7 +75,18 @@ public class ParachutePresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Diameter specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.DIAMETER,
ComponentPreset.LINE_COUNT,
ComponentPreset.LINE_LENGTH
},
new String[] {
"No Diameter specified",
"No LineCount specified",
"No LineLength specified"
}
);
} }
} }
@ -62,7 +100,16 @@ public class ParachutePresetTests {
presetspec.put( ComponentPreset.DIAMETER, 2.0); presetspec.put( ComponentPreset.DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No LineCount specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LINE_COUNT,
ComponentPreset.LINE_LENGTH
},
new String[] {
"No LineCount specified",
"No LineLength specified"
}
);
} }
} }
@ -77,7 +124,14 @@ public class ParachutePresetTests {
presetspec.put( ComponentPreset.LINE_COUNT, 6); presetspec.put( ComponentPreset.LINE_COUNT, 6);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No LineLength specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LINE_LENGTH
},
new String[] {
"No LineLength specified"
}
);
} }
} }

View File

@ -0,0 +1,43 @@
package net.sf.openrocket.preset;
import static org.junit.Assert.*;
public abstract class PresetTest {
public static void assertInvalidPresetException( InvalidComponentPresetException exceptions, TypedKey<?>[] keys, String[] messages ) {
if ( keys != null ) {
assertEquals( keys.length, exceptions.getInvalidParameters().size() );
for( TypedKey<?> expectedKey : keys ) {
boolean keyFound = false;
for( TypedKey<?> k : exceptions.getInvalidParameters() ) {
if ( expectedKey == k ) {
keyFound = true;
break;
}
}
if ( ! keyFound ) {
fail( "Expected key " + expectedKey + " not in exception");
}
}
} else {
assertEquals(0, exceptions.getInvalidParameters().size() );
}
if ( messages != null ) {
assertEquals( messages.length, exceptions.getErrors().size() );
for( String expectedMessage : messages ) {
boolean stringMatched = false;
for ( String s : exceptions.getErrors() ) {
if ( s.contains( expectedMessage ) ) {
stringMatched = true;
break;
}
}
if( !stringMatched ) {
fail( "Expected string \"" + expectedMessage + "\" not reported in errors");
}
}
} else {
assertEquals(0, exceptions.getErrors().size() );
}
}
}

View File

@ -1,6 +1,5 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
import org.junit.Test; import org.junit.Test;
@ -23,7 +22,20 @@ public class StreamerPresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.STREAMER); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.STREAMER);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.WIDTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"No Width specified"
}
);
} }
} }
@ -35,7 +47,18 @@ public class StreamerPresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.WIDTH
},
new String[] {
"No PartNo specified",
"No Length specified",
"No Width specified"
}
);
} }
} }
@ -48,7 +71,16 @@ public class StreamerPresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH,
ComponentPreset.WIDTH
},
new String[] {
"No Length specified",
"No Width specified"
}
);
} }
} }
@ -62,7 +94,14 @@ public class StreamerPresetTests {
presetspec.put( ComponentPreset.LENGTH, 2.0); presetspec.put( ComponentPreset.LENGTH, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Width specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.WIDTH
},
new String[] {
"No Width specified"
}
);
} }
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
import net.sf.openrocket.rocketcomponent.Transition; import net.sf.openrocket.rocketcomponent.Transition;
@ -27,7 +26,22 @@ public class TransitionPresetTests extends BaseTestCase {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.FORE_OUTER_DIAMETER
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"No AftOuterDiameter specified",
"No ForeOuterDiameter specified"
}
);
} }
} }
@ -39,7 +53,20 @@ public class TransitionPresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH,
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.FORE_OUTER_DIAMETER
},
new String[] {
"No PartNo specified",
"No Length specified",
"No AftOuterDiameter specified",
"No ForeOuterDiameter specified"
}
);
} }
} }
@ -52,7 +79,18 @@ public class TransitionPresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH,
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.FORE_OUTER_DIAMETER
},
new String[] {
"No Length specified",
"No AftOuterDiameter specified",
"No ForeOuterDiameter specified"
}
);
} }
} }
@ -67,7 +105,16 @@ public class TransitionPresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL); presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.AFT_OUTER_DIAMETER,
ComponentPreset.FORE_OUTER_DIAMETER
},
new String[] {
"No AftOuterDiameter specified",
"No ForeOuterDiameter specified"
}
);
} }
} }
@ -84,7 +131,14 @@ public class TransitionPresetTests extends BaseTestCase {
presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0); presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No ForeOuterDiameter")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.FORE_OUTER_DIAMETER
},
new String[] {
"No ForeOuterDiameter specified"
}
);
} }
} }

View File

@ -1,7 +1,6 @@
package net.sf.openrocket.preset; package net.sf.openrocket.preset;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import net.sf.openrocket.material.Material; import net.sf.openrocket.material.Material;
import net.sf.openrocket.motor.Manufacturer; import net.sf.openrocket.motor.Manufacturer;
@ -25,7 +24,19 @@ public class TubeCouplerPresetTests {
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER); presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.MANUFACTURER,
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No Manufacturer specified",
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -37,7 +48,17 @@ public class TubeCouplerPresetTests {
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer")); presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.PARTNO,
ComponentPreset.LENGTH
},
new String[] {
"No PartNo specified",
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -50,7 +71,15 @@ public class TubeCouplerPresetTests {
presetspec.put( ComponentPreset.PARTNO, "partno"); presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified")); PresetTest.assertInvalidPresetException( ex,
new TypedKey<?>[] {
ComponentPreset.LENGTH
},
new String[] {
"No Length specified",
"Preset dimensions underspecified"
}
);
} }
} }
@ -65,7 +94,12 @@ public class TubeCouplerPresetTests {
presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0); presetspec.put( ComponentPreset.OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -80,7 +114,12 @@ public class TubeCouplerPresetTests {
presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0); presetspec.put( ComponentPreset.INNER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }
@ -95,7 +134,12 @@ public class TubeCouplerPresetTests {
presetspec.put( ComponentPreset.THICKNESS, 2.0); presetspec.put( ComponentPreset.THICKNESS, 2.0);
ComponentPresetFactory.create(presetspec); ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) { } catch ( InvalidComponentPresetException ex ) {
assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified")); PresetTest.assertInvalidPresetException( ex,
null,
new String[] {
"Preset dimensions underspecified"
}
);
} }
} }