2013-04-05 2 views
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; 
     } 

    } 

} 

는 테스트 케이스 코드입니다 : equals를 들어

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

답변

1

당신이 Object 클래스에서 답변

+0

감사를 hashCode()equals(Object o)를 대체 할 사용자 지정 개체에서 작동 할 수 있습니다. 효과가 있습니다. – ram

관련 문제