From f7153203021f8e3b118be5429bf6b3bb8bbc1b62 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Sun, 6 May 2012 13:27:30 +0000 Subject: [PATCH] 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. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@649 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../preset/ComponentPresetFactory.java | 91 ++++++++++--------- .../InvalidComponentPresetException.java | 39 +++++++- .../preset/BodyTubePresetTests.java | 68 +++++++++++--- .../preset/BulkHeadPresetTests.java | 49 +++++++++- .../preset/CenteringRingPresetTests.java | 68 +++++++++++--- .../preset/EngineBlockPresetTests.java | 58 ++++++++++-- .../preset/LaunchLugPresetTests.java | 58 ++++++++++-- .../preset/NoseConePresetTests.java | 66 ++++++++++++-- .../preset/ParachutePresetTests.java | 66 ++++++++++++-- .../net/sf/openrocket/preset/PresetTest.java | 43 +++++++++ .../preset/StreamerPresetTests.java | 49 +++++++++- .../preset/TransitionPresetTests.java | 66 ++++++++++++-- .../preset/TubeCouplerPresetTests.java | 58 ++++++++++-- 13 files changed, 661 insertions(+), 118 deletions(-) create mode 100644 core/test/net/sf/openrocket/preset/PresetTest.java diff --git a/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java b/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java index 0315974a..e41bd9eb 100644 --- a/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java +++ b/core/src/net/sf/openrocket/preset/ComponentPresetFactory.java @@ -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); diff --git a/core/src/net/sf/openrocket/preset/InvalidComponentPresetException.java b/core/src/net/sf/openrocket/preset/InvalidComponentPresetException.java index 53066d13..c28fb093 100644 --- a/core/src/net/sf/openrocket/preset/InvalidComponentPresetException.java +++ b/core/src/net/sf/openrocket/preset/InvalidComponentPresetException.java @@ -1,25 +1,56 @@ package net.sf.openrocket.preset; +import java.util.ArrayList; +import java.util.List; + public class InvalidComponentPresetException extends Exception { + private List errors = new ArrayList(); + private List> invalidParameters = new ArrayList>(); + 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 getErrors() { + return errors; + } + + public List> getInvalidParameters() { + return invalidParameters; + } + } diff --git a/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java b/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java index 71582682..9e4ddf0e 100644 --- a/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java +++ b/core/test/net/sf/openrocket/preset/BodyTubePresetTests.java @@ -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); } diff --git a/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java b/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java index 047fe139..0cbfd28c 100644 --- a/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java +++ b/core/test/net/sf/openrocket/preset/BulkHeadPresetTests.java @@ -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" + } + ); } } diff --git a/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java b/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java index c1ec240f..109d15e5 100644 --- a/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java +++ b/core/test/net/sf/openrocket/preset/CenteringRingPresetTests.java @@ -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); } diff --git a/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java b/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java index 67971bc7..0c6ebf01 100644 --- a/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java +++ b/core/test/net/sf/openrocket/preset/EngineBlockPresetTests.java @@ -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" + } + ); } } diff --git a/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java b/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java index d37443b0..d2707f03 100644 --- a/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java +++ b/core/test/net/sf/openrocket/preset/LaunchLugPresetTests.java @@ -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" + } + ); } } diff --git a/core/test/net/sf/openrocket/preset/NoseConePresetTests.java b/core/test/net/sf/openrocket/preset/NoseConePresetTests.java index f36d026e..f82b5918 100644 --- a/core/test/net/sf/openrocket/preset/NoseConePresetTests.java +++ b/core/test/net/sf/openrocket/preset/NoseConePresetTests.java @@ -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" + } + ); } } diff --git a/core/test/net/sf/openrocket/preset/ParachutePresetTests.java b/core/test/net/sf/openrocket/preset/ParachutePresetTests.java index 321c96da..ad955699 100644 --- a/core/test/net/sf/openrocket/preset/ParachutePresetTests.java +++ b/core/test/net/sf/openrocket/preset/ParachutePresetTests.java @@ -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 index 00000000..ce42bb47 --- /dev/null +++ b/core/test/net/sf/openrocket/preset/PresetTest.java @@ -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() ); + } + } +} diff --git a/core/test/net/sf/openrocket/preset/StreamerPresetTests.java b/core/test/net/sf/openrocket/preset/StreamerPresetTests.java index 176cdb32..df84a4f3 100644 --- a/core/test/net/sf/openrocket/preset/StreamerPresetTests.java +++ b/core/test/net/sf/openrocket/preset/StreamerPresetTests.java @@ -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" + } + ); } } diff --git a/core/test/net/sf/openrocket/preset/TransitionPresetTests.java b/core/test/net/sf/openrocket/preset/TransitionPresetTests.java index 3b4928fc..45d9a1e3 100644 --- a/core/test/net/sf/openrocket/preset/TransitionPresetTests.java +++ b/core/test/net/sf/openrocket/preset/TransitionPresetTests.java @@ -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" + } + ); } } diff --git a/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java b/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java index 754eee51..296958b5 100644 --- a/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java +++ b/core/test/net/sf/openrocket/preset/TubeCouplerPresetTests.java @@ -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" + } + ); } } -- 2.30.2