Hi
Thanks for the reply. Here's what im trying to do:
I need to test a controller in which i need to instantiate a class and
use one of its methods.
Controller:
UserCredentials userCredentials = WebUserCredentialsUtils.from
(request);
StatusBean StatusBean = new StatusBean
(userCredentials.getSystem());
Collection<Group> Groups = statusBean.getgroupsAsMap().values
();
......
So i need to mock the instantiation of StatusBean class (it has no
corresponding interface). i tried doing sth. like :
statusBean = createMock(StatusBean.class, "SomeRegion");
expectNew(StatusBean.class, "SomeRegion").andReturn(statusBean);
expect(statusBean.getGroupsAsMap()).andReturn(groupMap);
replay(statusBean, StatusBean.class);
.....
I have all the jar files from the powermock zip with all dependencies.
But it still gives me an error at line :
statusBean = createMock(StatusBean.class, "SomeRegion");
java.lang.NoSuchMethodError:
org.easymock.classextension.internal.MocksClassControl.createMock
(Ljava/lang/Class;Lorg/easymock/classextension/ConstructorArgs;[Ljava/
lang/reflect/Method;)Ljava/lang/Object;
at org.powermock.api.easymock.PowerMock.doCreateMock(PowerMock.java:
2170)
at org.powermock.api.easymock.PowerMock.doMock(PowerMock.java:2140)
at org.powermock.api.easymock.PowerMock.createMock(PowerMock.java:
132)
at
com.ubs.swiskey.web.console.DashboardDisplayControllerMockitoTests.setup
(DashboardDisplayControllerMockitoTests.java:62)
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:585)
at org.junit.internal.runners.MethodRoadie.runBefores
(MethodRoadie.java:122)
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters
(MethodRoadie.java:86)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:
77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod
(JUnit4ClassRunner.java:88)
at org.junit.internal.runners.JUnit4ClassRunner.runMethods
(JUnit4ClassRunner.java:51)
at org.junit.internal.runners.JUnit4ClassRunner$1.run
(JUnit4ClassRunner.java:44)
at org.junit.internal.runners.ClassRoadie.runUnprotected
(ClassRoadie.java:27)
at org.junit.internal.runners.ClassRoadie.runProtected
(ClassRoadie.java:37)
at org.junit.internal.runners.JUnit4ClassRunner.run
(JUnit4ClassRunner.java:42)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run
(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run
(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests
(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run
(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main
(RemoteTestRunner.java:196)
I have tried mocking a new instance using Easymock/mockito but didnt
have much luck there. I was following this example for my requirement:
http://code.google.com/p/powermock/wiki/MockConstructor
Thanks
GT
On Aug 7, 1:10 am, Johan Haleby <
johan.hal...@gmail.com> wrote:
> Does that help? In that case I suspect that it can be a bug in our JUnit
> runner when you extend TestCase.
>
> On Fri, Aug 7, 2009 at 7:37 AM, gokul a <
gokul0...@gmail.com> wrote:
> > Hi,
>
> > Remove the "extends TestCase" from your test class.
>
> > Put "@Test" annotation in each of the test cases you have written and try.
>
> > Regards,
> > Gopal
>