Could someone please help:
I actually would prefer to use 'whenNew' on a different class but I have tried many variations and many classes without success.
There does not seem to be a logging mechanism that would inform me when things work or not so I feel I am working in the dark.
I also do not want to down the Spring configuration route as managing the Spring config files in this legacy project is a nightmare.
Also Tried - powermock-mockito2-testng-1.7.0 but got:
java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/MethodInterceptor.
Gave up after some time with Google and went back to powermock-mockito-testng-1.7.0.
Current Software environment:
Powermock: powermock-mockito-testng-1.7.0.
Java: 1.7
Eclipse: 4.6.3
Windows 10 Running in VirtualBox.
I am trying to Mock a method in a library class. This class is an import from another project and may have been compiled using Java 1.6 (possibly even 1.5).
The Class is a Legacy class that implements the Singleton pattern. It wraps SpringContext with a private constructor and a getInstance() method. It also has the following static method (Not sure why its static!):
public static Object getBean(String beanName)
My test code (Very much redacted due to company policies):
@RunWith(PowerMockRunner.class)
@PrepareForTest(SpringWrapper.class)
public class TestSW extends UnitTestBase {
@Test
public void testMock() {
try {
PowerMockito.mockStatic(SpringWrapper.class); // This is line 94! Does not get past here...
PowerMockito.when(SpringWrapper.getBean(Mockito.anyString())).thenReturn(null);
} catch (Exception e) {
e.printStackTrace();
}
}
}
at org.powermock.api.mockito.expectation.reporter.MockitoPowerMockReporter.classNotPrepared(MockitoPowerMockReporter.java:32)
at org.powermock.api.mockito.internal.mockcreation.MockTypeValidatorFactory$DefaultMockTypeValidator.validate(MockTypeValidatorFactory.java:38)
at org.powermock.api.mockito.internal.mockcreation.AbstractMockCreator.validateType(AbstractMockCreator.java:10)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.createMock(DefaultMockCreator.java:56)
at org.powermock.api.mockito.internal.mockcreation.DefaultMockCreator.mock(DefaultMockCreator.java:46)
at org.powermock.api.mockito.PowerMockito.mockStatic(PowerMockito.java:71)
at com.bt.*****************************************************.unit.TestSW.testMock(TestSW.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:643)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:820)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1128)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)
at org.testng.remote.RemoteTestNG.main(RemoteTestN
Current Software environment:Powermock: powermock-mockito-testng-1.7.0.Java: 1.7Eclipse: 4.6.3Windows 10 Running in VirtualBox.
Also Tried - powermock-mockito2-testng-1.7.0 but got:java.lang.NoClassDefFoundError: org/mockito/cglib/proxy/MethodInterceptor.
@RunWith(PowerMockRunner.class)@PrepareForTest(SpringWrapper.class)public class TestSW extends UnitTestBase {@Testpublic void testMock() {try {PowerMockito.mockStatic(SpringWrapper.class); // This is line 94! Does not get past here...PowerMockito.when(SpringWrapper.getBean(Mockito.anyString())).thenReturn(null);} catch (Exception e) {e.printStackTrace();}}}
--
You received this message because you are subscribed to the Google Groups "PowerMock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to powermock+...@googlegroups.com.
To post to this group, send email to powe...@googlegroups.com.
Visit this group at https://groups.google.com/group/powermock.
For more options, visit https://groups.google.com/d/optout.