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