1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

improved object comparison

This commit is contained in:
stleary 2015-04-23 21:42:04 -05:00
parent 5acbee2719
commit 30c86811c0

View file

@ -64,6 +64,20 @@ public class Util {
compareActualVsExpectedJsonArrays( compareActualVsExpectedJsonArrays(
jsonArray, expectedJsonArray); jsonArray, expectedJsonArray);
} else { } else {
/**
* Certain helper classes (e.g. XML) may create Long instead of
* Integer for small int values. As long as both are Numbers,
* just compare the toString() values.
*/
if (!(value instanceof Number && expectedValue instanceof Number)) {
assertTrue("object types should be equal for actual: "+
value.toString()+" ("+
value.getClass().toString()+") expected: "+
expectedValue.toString()+" ("+
expectedValue.getClass().toString()+")",
value.getClass().toString().equals(
expectedValue.getClass().toString()));
}
assertTrue("string values should be equal for actual: "+ assertTrue("string values should be equal for actual: "+
value.toString()+" expected: "+expectedValue.toString(), value.toString()+" expected: "+expectedValue.toString(),
value.toString().equals(expectedValue.toString())); value.toString().equals(expectedValue.toString()));
@ -83,4 +97,13 @@ public class Util {
} }
} }
public static void compareXML(String aXmlStr, String bXmlStr) {
// TODO For simple tests this may be adequate, but it won't work for
// elements with multiple attributes and possibly other cases as well.
// Should use XMLUnit or similar.
assertTrue("expected equal XML strings \naXmlStr: "+
aXmlStr+ "\nbXmlStr: " +bXmlStr, aXmlStr.equals(bXmlStr));
}
} }