JMockit - Expectations and static methods
-
27-10-2019 - |
سؤال
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:
- I'm getting a 'No current invocation available' at the returns call
- 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.
لا تنتمي إلى StackOverflow