My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 293: PM 1.4.6 does err's out mocking statics and private functions, or is inconsistent in mocking them
6 people starred this issue and may be notified of changes. Back to list
Status:  New
Owner:  ----


Sign in to add a comment
 
Reported by martinb...@gmail.com, Nov 17, 2010
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

PowerMockTest.zip
4.6 KB   Download
Nov 17, 2010
#1 martinb...@gmail.com
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");
    }
Dec 12, 2010
#3 sksum...@gmail.com
Somebody should look into this issue
Can anyone suggest a workaround?
Sign in to add a comment

Powered by Google Project Hosting