문제

I got this code in my junit:

new NonStrictExpectations(mPersonEvaluator) {
  {
    invoke(mPersonEvaluator, "doEvaluatePerson", withAny(String.class), withAny(Integer.class), withAny(Integer.class));
    result = doEvaluatePerson((String)any, (Integer)any, (Integer)any);  
  }
};

I want to generate the result from my private method doEvaluatePerson((String)any, (Integer)any, (Integer)any); everytime the method doEvaluatePerson is called in the business logic of mPersonEvaluator. The invoke works fine but the result is only calculated once during the setup of the junit and that result is null. My question is how can I declare such kind of usecase in jmockit so that the mock uses my private method?

Thank in advance

Stefan

도움이 되었습니까?

해결책

ok I found the answer. one possible solution is to use a Delegator like this:

   result = new Delegate<PersonArt>() {
      PersonArt delegator(String pShortName, Integer pOld, Integer pSize)
      {
         return doEvaluatePersonArt(pShortName, pOld, pSize);
      }
   };  

works pretty fine.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top