]> git.gag.com Git - debian/openrocket/commitdiff
Change the InvalidComponentPresetException so it reports all errors found in a preset...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sun, 6 May 2012 13:27:30 +0000 (13:27 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sun, 6 May 2012 13:27:30 +0000 (13:27 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@649 180e2498-e6e9-4542-8430-84ac67f01cd8

13 files changed:
core/src/net/sf/openrocket/preset/ComponentPresetFactory.java
core/src/net/sf/openrocket/preset/InvalidComponentPresetException.java
core/test/net/sf/openrocket/preset/BodyTubePresetTests.java
core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java
core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java
core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java
core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java
core/test/net/sf/openrocket/preset/NoseConePresetTests.java
core/test/net/sf/openrocket/preset/ParachutePresetTests.java
core/test/net/sf/openrocket/preset/PresetTest.java [new file with mode: 0644]
core/test/net/sf/openrocket/preset/StreamerPresetTests.java
core/test/net/sf/openrocket/preset/TransitionPresetTests.java
core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java

index 0315974a8a392c398fea6a28485565e642579ec2..e41bd9eb99c5d56b8a489313c3daf311b81eca73 100644 (file)
@@ -10,19 +10,22 @@ public abstract class ComponentPresetFactory {
 
        public static ComponentPreset create( TypedPropertyMap props ) throws InvalidComponentPresetException {
 
+               InvalidComponentPresetException exceptions = new InvalidComponentPresetException("Invalid preset specification.");
+               
                ComponentPreset preset = new ComponentPreset();
                // First do validation.
-               if ( !props.containsKey(TYPE)) {
-                       throw new InvalidComponentPresetException("No Type specified " + props.toString() );
-               }
-
                if (!props.containsKey(MANUFACTURER)) {
-                       throw new InvalidComponentPresetException("No Manufacturer specified " + props.toString() );
+                       exceptions.addInvalidParameter(MANUFACTURER, "No Manufacturer specified"); 
                }
-
                if (!props.containsKey(PARTNO)) {
-                       throw new InvalidComponentPresetException("No PartNo specified " + props.toString() );
+                       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;
+               }
+
 
                preset.putAll(props);
 
@@ -30,60 +33,64 @@ public abstract class ComponentPresetFactory {
                Type t = props.get(TYPE);
                switch ( t ) {
                case BODY_TUBE: {
-                       makeBodyTube(preset);
+                       makeBodyTube(exceptions,preset);
                        break;
                }
                case NOSE_CONE: {
-                       makeNoseCone(preset);
+                       makeNoseCone(exceptions,preset);
                        break;
                }
                case TRANSITION: {
-                       makeTransition(preset);
+                       makeTransition(exceptions,preset);
                        break;
                }
                case BULK_HEAD: {
-                       makeBulkHead(preset);
+                       makeBulkHead(exceptions,preset);
                        break;
                }
                case TUBE_COUPLER: {
                        // For now TUBE_COUPLER is the same as BODY_TUBE
-                       makeBodyTube(preset);
+                       makeBodyTube(exceptions,preset);
                        break;
                }
                case CENTERING_RING: {
-                       makeCenteringRing(preset);
+                       makeCenteringRing(exceptions,preset);
                        break;
                }
                case ENGINE_BLOCK: {
-                       makeEngineBlock(preset);
+                       makeEngineBlock(exceptions,preset);
                        break;
                }
                case LAUNCH_LUG: {
                        // Same processing as BODY_TUBE
-                       makeBodyTube(preset);
+                       makeBodyTube(exceptions,preset);
                        break;
                }
                case STREAMER: {
-                       makeStreamer(preset);
+                       makeStreamer(exceptions,preset);
                        break;
                }
                case PARACHUTE: {
-                       makeParachute(preset);
+                       makeParachute(exceptions,preset);
                        break;
                }
                }
 
+               if ( exceptions.hasProblems() ) {
+                       throw exceptions;
+               }
+               
                preset.computeDigest();
 
                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 );
                
@@ -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) ) {
                        // compute a density for this component
@@ -123,8 +130,8 @@ public abstract class ComponentPresetFactory {
 
        }
 
-       private static void makeTransition( ComponentPreset preset ) throws InvalidComponentPresetException {
-               checkRequiredFields(preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER);
+       private static void makeTransition( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+               checkRequiredFields(exceptions, preset, LENGTH, AFT_OUTER_DIAMETER, FORE_OUTER_DIAMETER);
 
                if ( preset.has(MASS) ) {
                        // compute a density for this component
@@ -145,8 +152,8 @@ public abstract class ComponentPresetFactory {
 
        }
 
-       private static void makeBulkHead( ComponentPreset preset ) throws InvalidComponentPresetException {
-               checkRequiredFields(preset, LENGTH, OUTER_DIAMETER );
+       private static void makeBulkHead( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+               checkRequiredFields(exceptions, preset, LENGTH, OUTER_DIAMETER );
 
                if ( preset.has(MASS) ) {
                        // compute a density for this component
@@ -167,10 +174,10 @@ public abstract class ComponentPresetFactory {
 
        }
 
-       private static void makeCenteringRing( ComponentPreset preset ) throws InvalidComponentPresetException {
-               checkRequiredFields( preset, LENGTH );
+       private static void makeCenteringRing( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
+               checkRequiredFields( exceptions, preset, LENGTH );
 
-               checkDiametersAndThickness( preset );
+               checkDiametersAndThickness( exceptions, preset );
 
                double volume = computeVolumeOfTube( preset );
 
@@ -186,10 +193,10 @@ public abstract class ComponentPresetFactory {
 
        }
        
-       private static void makeEngineBlock( ComponentPreset preset ) throws InvalidComponentPresetException {
-               checkRequiredFields( preset, LENGTH );
+       private static void makeEngineBlock( InvalidComponentPresetException exceptions, ComponentPreset preset ) throws InvalidComponentPresetException {
+               checkRequiredFields( exceptions, preset, LENGTH );
 
-               checkDiametersAndThickness( preset );
+               checkDiametersAndThickness( exceptions, preset );
 
                double volume = computeVolumeOfTube( preset );
 
@@ -205,24 +212,24 @@ public abstract class ComponentPresetFactory {
 
        }
        
-       private static void makeStreamer( ComponentPreset preset ) throws InvalidComponentPresetException {
-               checkRequiredFields( preset, LENGTH, WIDTH );
+       private static void makeStreamer( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+               checkRequiredFields( exceptions, preset, LENGTH, WIDTH );
        }
 
-       private static void makeParachute( ComponentPreset preset ) throws InvalidComponentPresetException {
-               checkRequiredFields( preset, DIAMETER, LINE_COUNT, LINE_LENGTH );
+       private static void makeParachute( InvalidComponentPresetException exceptions, ComponentPreset preset ) {
+               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 ) {
                        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.
                boolean hasOd = preset.has(OUTER_DIAMETER);
                boolean hasId = preset.has(INNER_DIAMETER);
@@ -242,11 +249,13 @@ public abstract class ComponentPresetFactory {
                                thickness = preset.get(THICKNESS);
                                innerRadius = outerRadius - thickness;
                        } else {
-                               throw new InvalidComponentPresetException("Preset underspecified " + preset.toString());
+                               exceptions.addMessage("Preset dimensions underspecified");
+                               throw exceptions;
                        }
                } else {
                        if ( ! hasId || ! hasThickness ) {
-                               throw new InvalidComponentPresetException("Preset underspecified " + preset.toString());
+                               exceptions.addMessage("Preset dimensions underspecified");
+                               throw exceptions;
                        }
                        innerRadius = preset.get(INNER_DIAMETER)/2.0;
                        thickness = preset.get(THICKNESS);
index 53066d13c70dd0a00ab86c6aeb273387c865aa30..c28fb09304c161d1fa16f084488897546c427802 100644 (file)
@@ -1,25 +1,56 @@
 package net.sf.openrocket.preset;
 
+import java.util.ArrayList;
+import java.util.List;
+
 public class InvalidComponentPresetException extends Exception {
 
+       private List<String> errors = new ArrayList<String>();
+       private List<TypedKey<?>> invalidParameters = new ArrayList<TypedKey<?>>();
+       
        public InvalidComponentPresetException() {
                super();
-               // TODO Auto-generated constructor stub
        }
 
        public InvalidComponentPresetException(String message, Throwable cause) {
                super(message, cause);
-               // TODO Auto-generated constructor stub
        }
 
        public InvalidComponentPresetException(String message) {
                super(message);
-               // TODO Auto-generated constructor stub
        }
 
        public InvalidComponentPresetException(Throwable 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;
+       }
+       
 }
index 71582682cd2097b88c022a830bd1afb15378ab86..9e4ddf0e814f71a138186d28ef194ff77b90c267 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 
@@ -25,7 +24,19 @@ public class BodyTubePresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BODY_TUBE);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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.
                double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
                volume *= 2.0; /* times length */
-               
+
                double density = 100.0 / volume;
-               
+
                assertEquals("TubeCustom",preset.get(ComponentPreset.MATERIAL).getName());
                assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
        }
@@ -196,7 +240,7 @@ public class BodyTubePresetTests {
 
                assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
                assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
-               
+
        }
 
        @Test
@@ -217,9 +261,9 @@ public class BodyTubePresetTests {
                // constants put into the presetspec above.
                double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
                volume *= 2.0; /* times length */
-               
+
                double density = 100.0 / volume;
-               
+
                assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
                assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
        }
index 047fe1395742dc51a4e4f767a1bc0f9230a6a806..0cbfd28c18edffc0c403ba93c499a8034d18b39b 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 
@@ -25,7 +24,20 @@ public class BulkHeadPresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.BULK_HEAD);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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"
+                       }
+                                       );
                }
        }
 
index c1ec240fce89dd9e714d3ecbc1bb8e15876d28fd..109d15e5e2a95c7546b4c0a202517f15fc766874 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 
@@ -25,7 +24,19 @@ public class CenteringRingPresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.CENTERING_RING);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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.
                double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
                volume *= 2.0; /* times length */
-               
+
                double density = 100.0 / volume;
-               
+
                assertEquals("CenteringRingCustom",preset.get(ComponentPreset.MATERIAL).getName());
                assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
        }
@@ -196,7 +240,7 @@ public class CenteringRingPresetTests {
 
                assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
                assertEquals(2.0,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
-               
+
        }
 
        @Test
@@ -217,9 +261,9 @@ public class CenteringRingPresetTests {
                // constants put into the presetspec above.
                double volume = /*outer area*/ (Math.PI * 1.0) - /* inner area */ (Math.PI * .25);
                volume *= 2.0; /* times length */
-               
+
                double density = 100.0 / volume;
-               
+
                assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
                assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.0005);
        }
index 67971bc7f8915b6c6691c4eecac1e1c3c469d525..0c6ebf01fea8eb31338f2fc1aed9cd5593da1ea9 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 
@@ -25,7 +24,19 @@ public class EngineBlockPresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.ENGINE_BLOCK);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } catch ( InvalidComponentPresetException ex ) {
-                       assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+                       PresetTest.assertInvalidPresetException( ex,
+                                       null,
+                       new String[] {
+                                       "Preset dimensions underspecified"
+                       }
+                                       );
                }
        }
 
index d37443b03584e618f8b2d7f077932121e4668cb3..d2707f03bc8ff18358e30a0b8c582cd79c06a8af 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 
@@ -25,7 +24,19 @@ public class LaunchLugPresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.LAUNCH_LUG);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } catch ( InvalidComponentPresetException ex ) {
-                       assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+                       PresetTest.assertInvalidPresetException( ex,
+                                       null,
+                       new String[] {
+                                       "Preset dimensions underspecified"
+                       }
+                                       );
                }
        }
 
index f36d026efe08e771cd358ce7f029ee1e210eec01..f82b59189633116e2f14e1b8841a7d81b656d475 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 import net.sf.openrocket.rocketcomponent.Transition;
@@ -27,7 +26,22 @@ public class NoseConePresetTests extends BaseTestCase {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.NOSE_CONE);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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"
+                       }
+                                       );
                }
        }
 
index 321c96da6edf57e9c2259ce4bd10b970e3136847..ad9556990efb00f10ac4f734548168174fee3ff7 100644 (file)
@@ -1,6 +1,5 @@
 package net.sf.openrocket.preset;
 
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.motor.Manufacturer;
 
 import org.junit.Test;
@@ -23,7 +22,22 @@ public class ParachutePresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.PARACHUTE);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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"
+                       }
+                                       );
                }
        }
 
diff --git a/core/test/net/sf/openrocket/preset/PresetTest.java b/core/test/net/sf/openrocket/preset/PresetTest.java
new file mode 100644 (file)
index 0000000..ce42bb4
--- /dev/null
@@ -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() );
+               }
+       }
+}
index 176cdb3270e75b65305f9bb19508950615e78cb9..df84a4f38102bded418389cfe9ea5f57c4ea9b0b 100644 (file)
@@ -1,6 +1,5 @@
 package net.sf.openrocket.preset;
 
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.motor.Manufacturer;
 
 import org.junit.Test;
@@ -23,7 +22,20 @@ public class StreamerPresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.STREAMER);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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"
+                       }
+                                       );
                }
        }
 
index 3b4928fc6a36b20bd5f8b8f5fc08b5f7329467b3..45d9a1e37785f8a311b88e8558b6a560a1cf3388 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 import net.sf.openrocket.rocketcomponent.Transition;
@@ -27,7 +26,22 @@ public class TransitionPresetTests extends BaseTestCase {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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"
+                       }
+                                       );
                }
        }
 
index 754eee51192a59630deccaa88f6150edc78d7c0c..296958b5818520be2f11502c97b74be94e871d09 100644 (file)
@@ -1,7 +1,6 @@
 package net.sf.openrocket.preset;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import net.sf.openrocket.material.Material;
 import net.sf.openrocket.motor.Manufacturer;
 
@@ -25,7 +24,19 @@ public class TubeCouplerPresetTests {
                        presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TUBE_COUPLER);
                        ComponentPresetFactory.create(presetspec);
                } 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"));
                        ComponentPresetFactory.create(presetspec);
                } 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");
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } 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);
                        ComponentPresetFactory.create(presetspec);
                } catch ( InvalidComponentPresetException ex ) {
-                       assertTrue("Wrong Exception Thrown", ex.getMessage().contains("Preset underspecified"));
+                       PresetTest.assertInvalidPresetException( ex,
+                                       null,
+                       new String[] {
+                                       "Preset dimensions underspecified"
+                       }
+                                       );
                }
        }