2011-03-16 7 views
1

글쎄, 지금 레거시 코드를 테스트 중입니다. 그리고, 나는이 시험을 통과 할 수있는 가까운 곳이지만, 그것에 대한 의견이있는 라인에 붙어있다. 여기에 조각 result의 모든 값이 조롱하는, 반면테스트중인 클래스의 개인 메서드로 호출을 바꾸는 방법

new NonStrictExpectations(){ 
     SASCustomerDataAssemblerBD assembleBd; 
     CustomerTOs tos; 
     CustomerSASTO to; 
     Another rowTo; 
     SelectionJobLogBD logBd;  

     { 
       SASCustomerDataAssemblerBD.getInstanceUsingEjbRef(); result = assembleBd; 
       assembleBd.getData(); result = tos; 
       .. 
       .. 
       //This line is not being invoked. 
       //Instead the actual line of code is working. Which is, 
       //Collections.max(someCollection, someComparator); 
       //Hence I am stuck because getting null in "to" 
       invoke(Collections.class, "max", new ArrayList(), new MaxDateComparator()); result = to; 
       to.getSasDataRow(); result = rowTo; 
       SelectionJobLogBD.getInstanceUsingEjbRef(); result = logBd;         
       .. 
     } 
    }; 

    new TaskSASCustomerReading().execute(); 

에게 있습니다.

+0

다른 곳에서 인스턴스가 생성되는 'to'입니까? – Feanor

+0

@Feanor : 모형 (mockup) 인스턴스입니다. –

+0

'mockup instance'는 결과가 'to'에 할당 된이 NonStrictExpectations 레코드 단계에 다른 호출이 있음을 명확히하기 위해? – Feanor

답변

2

해결 방법은 다른 방법입니다. 원래 방법을 조롱했다 - 후드 아래 Collections.max()을 호출하는 메서드 만. 나는이 질문을 할 때

new MockUp<TaskSASCustomerReading>() 
    { 
     @Mock 
     // This original method is invoking Collections.max(). 
     // Therefore, I just mocked this one, other methods are all original 
     String findLatestSelectionDate(Collection customerTOs) { 
      return ""; 
     } 
    }; 

    new Expectations(){ 
     SASCustomerDataAssemblerBD assembleBd; 
     CustomerTOs tos;   
     SelectionJobLogBD logBd; 
     { 
      try { 
       SASCustomerDataAssemblerBD.getInstanceUsingEjbRef(); result = assembleBd; 
       assembleBd.getData(); result = tos; 
       SelectionJobLogBD.getInstanceUsingEjbRef(); result = logBd;         
      }catch(Exception e){} 
     } 
    }; 

    new TaskSASCustomerReading().execute(); 

없음 적은, 나는 완전히, 처음에 일을 오해하지 않았다. 내 원래의 질문에, 나는 그것을 대체하는 대신 실제로 메소드를 호출하려고합니다. (P.S. 시간 이후에 작업하지 마십시오.))

관련 문제