*/
public void testMapOnlyStoresAllowableTypes() {
MetaDataFactory f = MetaDataFactory.getDefaultInstance();
String key = "key";
BooleanValue allowableValue = (BooleanValue) f.getValueFactory()
.createBooleanValue();
Object forbiddenValue = new Integer(1);
// create the map so that it only allows allowable values and keys
TypedMap typedMap = createTypedMap(new HashMap(),
allowableValue.getClass(), false);
// test that we can add an allowable value with an allowable key
try {
typedMap.put(key, allowableValue);
} catch (IllegalArgumentException e) {
fail("Adding a " + allowableValue.getClass() + " value with a "
+ key.getClass() + " key should be permitted.");
}
// test that we can not add a forbidden value with an allowable key
try {
typedMap.put(key, forbiddenValue);
fail("Adding a forbidden value with an allowed key should not be " +
"permitted. Allowed value: " + allowableValue.getClass()
+ " forbidden value : " + forbiddenValue.getClass());
} catch (IllegalArgumentException e) {
// expected
}
}