0

我正在编写一个测试用例,我需要比较两个包含嵌套对象的数组对象。这是示例代码,请检查。

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;
        }

    }

}

这是测试用例代码:

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));
4

1 回答 1

1

equals处理自定义对象,您必须覆盖hashCode()equals(Object o)Object类中

于 2013-04-05T05:16:55.017 回答