try {
// Now check that hashCode and equals are affected by values of different fields.
for(MethodAndArgs currentMethod:MethodsArgs)
{
Configuration
configA = Configuration.getDefaultConfiguration().copy(),
configB = Configuration.getDefaultConfiguration().copy();
for(MethodAndArgs orig:MethodsArgs)
{
orig.method.invoke(configA, new Object[]{orig.Arg});
orig.method.invoke(configB, new Object[]{orig.Arg});
}
Assert.assertEquals(configB, configA);
// now test that we can serialise these
{
org.w3c.dom.Element xmlB = configB.writeXML(doc),xmlA=configA.writeXML(doc);
Configuration loadedB=new Configuration();loadedB.readXML(xmlB);Configuration loadedA=new Configuration();loadedA.readXML(xmlA);
Assert.assertEquals(loadedB, loadedA);
Assert.assertEquals(loadedB, configA);
}
currentMethod.method.invoke(configB, new Object[]{currentMethod.AlternativeArg});
String errMsg = "configurations differ: field "+currentMethod.field+" is not in use for ";
Assert.assertFalse(errMsg+"equals",configB.equals(configA));
Assert.assertFalse(errMsg+"equals",configA.equals(configB));
{
org.w3c.dom.Element xmlB = configB.writeXML(doc),xmlA=configA.writeXML(doc);
Configuration loadedB=new Configuration();loadedB.readXML(xmlB);Configuration loadedA=new Configuration();loadedA.readXML(xmlA);
Assert.assertEquals(loadedA, configA);
Assert.assertFalse(errMsg+"equals",loadedB.equals(loadedA));
Assert.assertFalse(errMsg+"equals",loadedB.equals(configA));
Assert.assertFalse(errMsg+"equals",loadedA.equals(loadedB));
}
Assert.assertTrue(errMsg+"hashCode",configA.hashCode() != configB.hashCode());
}
} catch (Exception e) {