Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM 1.4.6 does err's out mocking statics and private functions, or is inconsistent in mocking them #313

Open
johanhaleby opened this issue Jul 24, 2015 · 2 comments

Comments

@johanhaleby
Copy link
Collaborator

From martinb...@gmail.com on November 17, 2010 22:53:46

Using Java 6, TestNG 5.14.2, EasyMock 3 and PM1.4.6, cannot get @PrepareForTest and subsequent mocking of private or static methods to succeed.

Mocking err's out during setting the mocks expectations.

The given tests should all work per the PowerMock documentation, though all four tests fail in Eclipse 3.6 and only one works in Maven. Test are performed with/without extending PowerMockTestCase.

Errors occur setting expectations deeper in EasyMock . Example stack trace below:

FAILED: testGetSIAGood
java.lang.IllegalStateException: no last call on a mock available
at org.easymock. EasyMock .getControlForLastCall( EasyMock .java:521)
at org.easymock. EasyMock .expectLastCall( EasyMock .java:512)
at org.powermock.api.easymock.PowerMock.doExpectPrivate(PowerMock.java:2247)
at org.powermock.api.easymock.PowerMock.expectPrivate(PowerMock.java:1409)
at org.powermock.api.easymock.PowerMock.expectPrivate(PowerMock.java:1420)
at org.powermock.api.easymock.PowerMock.expectPrivate(PowerMock.java:1366)
at IAXPMUCTest.testGetSIAGood(IAXPMUCTest.java:73)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:74)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:675)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:848)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1170)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1119)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:600)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:317)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:312)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:274)
at org.testng.SuiteRunner.run(SuiteRunner.java:223)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:957)
at org.testng.TestNG.runSuitesLocally(TestNG.java:886)
at org.testng.TestNG.run(TestNG.java:820)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:110)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:205)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:174)

Attached is a zip of the Maven project.

Thanks

Martin

Attachment: PowerMockTest.zip

Original issue: http://code.google.com/p/powermock/issues/detail?id=293

@johanhaleby
Copy link
Collaborator Author

From martinb...@gmail.com on November 17, 2010 14:35:49

Tried updating the SetUp to use staticMock, with the same result as above. The code would read:

@BeforeClass
public void setUp() throws UnknownHostException {
    addr = InetAddress.getLocalHost();
    uhe = new UnknownHostException("Dummy UHE");
    classUnderTest =
        PowerMock.createPartialMock(IAX.class, "getLocalHost");
    PowerMock.mockStaticPartial(IAX.class, "getStaticLocalHost");
}

@johanhaleby
Copy link
Collaborator Author

From sksum...@gmail.com on December 12, 2010 21:45:50

Somebody should look into this issue
Can anyone suggest a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant