문제

I'm trying to mock a method to have it return one specific object:

  private static final String PARAM = "somevalue";
  ...
  @Test
  public void jmockit() {

   final PojoClass dfault = new PojoClass();

   new NonStrictExpectations() {
       StaticFacade mcfg;
       {
          StaticFacade.getPojo(PARAM); returns(dfault);
       }
    };

    PojoClass a = StaticFacade.getPojo(PARAM);

    assertNotNull(a);

 }

But I'm facing 2 issues:

  1. I'm getting a 'No current invocation available' at the returns call
  2. If I try to add the result variable I get compilation problems.

I'm using JDK1.5. Any ideas?

도움이 되었습니까?

해결책

So looks like in the end it was a setup issue: I had an older version of JMockit and a eclipse signed JUnit jar. Updating the jars to the latest versions (Jmockit 0.999-12 and JUnit 4.10) fixed the issue.

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