}
public void testVerify() {
// create the test type
final MutableQuantityType quantityType =
TYPE_FACTORY.createQuantityType();
final MutableNumberType numberType = TYPE_FACTORY.createNumberType();
final ImmutableNumberSubTypeConstraint subTypeConstraint =
CONSTRAINT_FACTORY.getNumberSubTypeConstraint(Integer.class);
numberType.setNumberSubTypeConstraint(subTypeConstraint);
quantityType.setMagnitudeType(numberType);
final MutableUnitType unitType = TYPE_FACTORY.createUnitType();
final MutableEnumeratedConstraint enumeratedConstraint =
CONSTRAINT_FACTORY.createEnumeratedConstraint();
final List enumeratedValues =
enumeratedConstraint.getMutableEnumeratedValues();
enumeratedValues.add(QuantityUnits.MILLIMETERS);
enumeratedValues.add(QuantityUnits.CENTIMETERS);
enumeratedValues.add(QuantityUnits.INCHES);
unitType.setEnumeratedConstraint(enumeratedConstraint);
quantityType.setUnitType(unitType);
// normal case
MutableQuantityValue quantityValue = VALUE_FACTORY.createQuantityValue();
final MutableNumberValue magnitudeValue =
VALUE_FACTORY.createNumberValue();
magnitudeValue.setValue(new Integer(123));
quantityValue.setMagnitudeValue(magnitudeValue);
quantityValue.setUnitValue(QuantityUnits.CENTIMETERS);
Collection errors = quantityType.verify(quantityValue);
assertEquals(0, errors.size());
// invalid magnitude type
magnitudeValue.setValue(new Byte((byte) 42));
quantityValue.setMagnitudeValue(magnitudeValue);
errors = quantityType.verify(quantityValue);
assertEquals(1, errors.size());
VerificationError error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("[@magnitude]", error.getLocation());
assertEquals(magnitudeValue, error.getInvalidValue());
assertEquals(subTypeConstraint, error.getConstraint());
// invalid unit type
magnitudeValue.setValue(new Integer(42));
quantityValue.setMagnitudeValue(magnitudeValue);
quantityValue.setUnitValue(QuantityUnits.PIXELS);
errors = quantityType.verify(quantityValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_CONSTRAINT_VIOLATION,
error.getType());
assertEquals("[@unit]", error.getLocation());
assertEquals(QuantityUnits.PIXELS, error.getInvalidValue());
assertEquals(enumeratedConstraint, error.getConstraint());
// invalid type
BooleanValue booleanValue = VALUE_FACTORY.createBooleanValue();
errors = quantityType.verify(booleanValue);
assertEquals(1, errors.size());
error = (VerificationError) errors.iterator().next();
assertEquals(VerificationError.TYPE_INVALID_IMPLEMENTATION,
error.getType());
assertEquals("", error.getLocation());