I am trying to just run a simple test case. I have the following method.
public static void run(String[] args) throws Throwable { CommandLineArguments opts = CommandLineOptionProcessor.getOpts(args); }
I will continue this method / test case when I go. However, I just wanted to make sure that the first test case worked first. So I wrote the following test.
@Test public void testRun() { String[] args = {"--arg1", "value", "--arg2", "value2"}; mockStatic(CommandLineOptionProcessor.class); expect(CommandLineOptionProcessor.getOpts(args)); EasyMock.replay(CommandLineOptionProcessor.class); }
After that, I get the following error:
java.lang.IllegalStateException: no last call on a mock available
I read some other posts on StackOverflow, but their solution seemed to use PowerMock with Mockito. I use Powermock and Easymock, so this should not be a problem.
I followed Reneβs advice and added the following to the beginning of my class.
@PrepareForTest(CommandLineOptionProcessor.class) @RunWith(PowerMockRunner.class) public class DataAssemblerTest {
I fixed the previous error. But now I have this error.
java.lang.IllegalArgumentException: Not a mock: java.lang.Class at org.easymock.internal.ClassExtensionHelper.getControl(ClassExtensionHelper.java:61) at org.easymock.EasyMock.getControl(EasyMock.java:2172) at org.easymock.EasyMock.replay(EasyMock.java:2074) . . .
Any ideas on what might be causing this will be great.
java unit-testing junit powermock easymock
Cameron jones
source share