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;
presetspec.put(ComponentPreset.TYPE, ComponentPreset.Type.TRANSITION);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Manufacturer specified"));
+ PresetAssertHelper.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"
+ }
+ );
}
}
presetspec.put( ComponentPreset.MANUFACTURER, Manufacturer.getManufacturer("manufacturer"));
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No PartNo specified"));
+ PresetAssertHelper.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"
+ }
+ );
}
}
presetspec.put( ComponentPreset.PARTNO, "partno");
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No Length specified"));
+ PresetAssertHelper.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"
+ }
+ );
}
}
presetspec.put( ComponentPreset.SHAPE, Transition.Shape.CONICAL);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No AftOuterDiameter"));
+ PresetAssertHelper.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.AFT_OUTER_DIAMETER,
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No AftOuterDiameter specified",
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
ComponentPresetFactory.create(presetspec);
} catch ( InvalidComponentPresetException ex ) {
- assertTrue("Wrong Exception Thrown", ex.getMessage().contains("No ForeOuterDiameter"));
+ PresetAssertHelper.assertInvalidPresetException( ex,
+ new TypedKey<?>[] {
+ ComponentPreset.FORE_OUTER_DIAMETER
+ },
+ new String[] {
+ "No ForeOuterDiameter specified"
+ }
+ );
}
}
double density = 100.0 / volume;
assertEquals("TransitionCustom",preset.get(ComponentPreset.MATERIAL).getName());
- // FIXME - I would expect the nc volume computation to be closer for such a simple shape.
- // simple math yields 27.2837
- // 100/nc.getComponentVolume yields 27.59832
- assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.5);
+
+ assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density);
}
@Test
presetspec.put( ComponentPreset.AFT_OUTER_DIAMETER, 2.0);
presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0);
presetspec.put( ComponentPreset.FILLED, true);
- presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
+ presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0));
ComponentPreset preset = ComponentPresetFactory.create(presetspec);
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
presetspec.put( ComponentPreset.FORE_OUTER_DIAMETER, 1.0);
presetspec.put( ComponentPreset.FILLED, true);
presetspec.put( ComponentPreset.MASS, 100.0);
- presetspec.put( ComponentPreset.MATERIAL, new Material.Bulk("test", 2.0, true));
+ presetspec.put( ComponentPreset.MATERIAL, Material.newUserMaterial(Material.Type.BULK,"test", 2.0));
ComponentPreset preset = ComponentPresetFactory.create(presetspec);
// constants put into the presetspec above.
double density = 100.0 / volume;
assertEquals("test",preset.get(ComponentPreset.MATERIAL).getName());
- // FIXME - I would expect the nc volume computation to be closer for such a simple shape.
- assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),1.5);
+
+ assertEquals(density,preset.get(ComponentPreset.MATERIAL).getDensity(),0.01*density);
}
}