return new ImmutableEnumeratedConstraintImpl();
}
// Javadoc inherited.
public void testEqualsAndHashcodeImplementedCorrectly() {
MutableEnumeratedConstraint enumeratedConstraint1 =
createEnumeratedConstraintForTestEquals();
MutableEnumeratedConstraint enumeratedConstraint2 =
createEnumeratedConstraintForTestEquals();
// test that both the values are equal and they have the same hash codes
assertEquals("Object 1 should be equal to object 2", enumeratedConstraint1,
enumeratedConstraint2);
int booleanType1Hashcode = enumeratedConstraint1.hashCode();
int booleanType2Hashcode = enumeratedConstraint2.hashCode();
assertTrue("Objects which are equal should have the same hash codes. Were : "
+ booleanType1Hashcode + " and " + booleanType2Hashcode,
booleanType1Hashcode == booleanType2Hashcode);
// change a property in one of the objects and ensure they are not equal
MutableBooleanValue booleanValue = MetaDataFactory.getDefaultInstance().
getValueFactory().createBooleanValue();
enumeratedConstraint2.getMutableEnumeratedValues().add(booleanValue);
assertNotEquals(enumeratedConstraint1, enumeratedConstraint2);
assertNotEquals(enumeratedConstraint2, enumeratedConstraint1);
// ensure that the hashcodes are different for these two objects
booleanType1Hashcode = enumeratedConstraint1.hashCode();
booleanType2Hashcode = enumeratedConstraint2.hashCode();
assertFalse("Objects which are not equal should ideally have different hash codes",
booleanType1Hashcode == booleanType2Hashcode);
}