2014-03-18 3 views
0
@Test 
    public void test_getAllIngredientsExcept_Parameter_Valid_List()throws DatabaseException, ServiceException, DomainException{ 
     System.err.println(this.validShoppingFacade.getAllIngredients()); 
     this.validShoppingFacade.addIngredient(validIngredient); 
     Collection<Ingredient> expected = new ArrayList<Ingredient>(this.validShoppingFacade.getAllIngredients()); 

     this.validShoppingFacade.addIngredient(anotherValidIngredient); 
     System.err.println(this.validShoppingFacade.getAllIngredients()); 
     Collection<Ingredient> ingredientExceptions = new ArrayList<Ingredient>(); 
     ingredientExceptions.add(anotherValidIngredient); 

     System.err.println(this.validShoppingFacade.getAllIngredients()); 
     System.err.println((List<Ingredient>)validShoppingFacade.getAllIngredientsExcept(ingredientExceptions)); 
     assertEquals(expected,(List<Ingredient>)validShoppingFacade.getAllIngredientsExcept(ingredientExceptions)); 
    } 

sys.err의컬렉션 참조

'[성분 {NAME = ingredient1 수량 = 0.25Kg, ID = 1}, {성분 NAME = ingredient2 수량 = 0.3L, ID = 2} 성분 {이름 = 성분 1, 양 = 0.25Kg, id = 1}, 성분 {이름 = 성분 2, 양 = 수량, 0.3L, 성분 = 2}, 성분 {이름 = 성분 1, 양 = 0.25Kg, 이데스 = 3}, 성분 {이름 = 성분 2, 양 = 0.3L, 성분 = 4}]

[성분 {이름 = 성분 1, 양 = 0.25Kg, id = 1} 성분 {이름 = 성분 2, 양 = 0.3L, 성분 = 2}, 성분 {이름 = 성분 1, 양 = 0.25Kg, 성분 = 3}, 성분 {이름 = 성분 2, 양 = 0.3L, 성분 = 4}

위한

[성분 {NAME = ingredient1 수량 = 0.25Kg, ID = 1}, {성분 NAME = ingredient1 수량 = 0.25Kg, ID = 3}] '

헬로

미안 모호한 제목이지만 나는 그것을 다른 말로 표현할 방법을 모른다. -

이 질문 문제 현재 내가 메시지를 얻을 :

예상 : < [성분 {이름 = ingredient1, 수량 = 0.25Kg, ID = 1}, 성분 {이름 = ingredient2, 수량 = < [성분 {이름 = 성분 1, 양 = 0.25 킬로그램, id = 1}, 성분 {이름 = 성분 1, 양 = 0.25 킬로그램, id = 3} 성분 1, 양 = 0.25Kg, id = 3}]>

그래서 코드는 작동하지만 테스트 항목은 esnt, 내가 아는 한 버그는 Collection<Ingredient> expected = new ArrayList<Ingredient>(this.validShoppingFacade.getAllIngredients()); 안에 있습니다. 예상되는 목록은 단지 Facade의 목록에 대한 참조 일뿐입니다. 내가 예상 목록에 추가하기 위해 facde 목록에서 for 루프를 실행한다면 작동하지만, 그것은 "테스트 케이스"에 대해 이상하게 보입니다.

답변

1

문제점이 마지막 인쇄 문

인쇄해야 (List<Ingredient>)validShoppingFacade.getAllIngredientsExcept(ingredientExceptions)

에 놓여있다

[성분 {NAME = ingredient1 수량 = 0.25Kg, ID = 1}, 성분 {NAME = ingredient2 수량 = 0.3L, ID = 2}, {성분 NAME = ingredient1 수량 = 0.25Kg, ID = 3}]

System.err.println((List<Ingredient>)validShoppingFacade.getAllIngredientsExcept(ingredientExceptions)); 

이 누락 ID = 3 객체. getAllIngredientsExcept() 메소드 구현을 게시 할 수 있습니까?

+0

Ingrediënt 클래스의 Equals는 이름에만 기반하므로 같은 이름을 가지고 있으므로 show id = 3이 아닙니다. (내가 지금해야 할 일은, 사용자 잘못 이었기 때문에 질문에 답을하거나 답을해라.) –

0

assertEquals 두 개의 목록이 동일한 포인터인지 확인하려는 Object.equals()을 호출하려고합니다. 아마도 시도하십시오 assertTrue(org.apache.commons.collections.CollectionUtils.isEqualCollection(expected, (List<Ingredient>)validShoppingFacade.getAllIngredientsExcept(ingredientExceptions))