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:
parent
5acbee2719
commit
30c86811c0
1 changed files with 23 additions and 0 deletions
23
Util.java
23
Util.java
|
@ -64,6 +64,20 @@ public class Util {
|
|||
compareActualVsExpectedJsonArrays(
|
||||
jsonArray, expectedJsonArray);
|
||||
} 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: "+
|
||||
value.toString()+" expected: "+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));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue