Pergunta

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?

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top