我正在编写一个测试用例,我需要比较两个包含嵌套对象的数组对象。以下是示例代码,请查看。
Class TestGeoNames {
private Status status;
public void setStatus(Status lstatus) {
status = lstatus;
}
public Class Status {
private String mesg;
private String value;
public String getMesg() {
return mesg;
}
public void setMesg(String mesg) {
this.mesg = mesg;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
}
以下是testCase代码:
List<TestGeoNames > result = NetworkManager.executeByJSON(request, TestGeoNames .class);
List<TestGeoNames > Cacheresult = CacheManager.getResponseFromCache(request);
assertNotNull(result);
assertNotNull(Cacheresult);
TestGeonamesBean[] tgb = new TestGeonamesBean[0];
TestGeonamesBean[] cacheResultArray = result.toArray(tgb);
TestGeonamesBean[] resultArray = Cacheresult.toArray(tgb);
assertEquals(true, Arrays.equals(resultArray, cacheResultArray));
答案 0 :(得分:1)
要让equals
处理自定义对象,您必须覆盖hashCode()
类
equals(Object o)
和Object