NoSuchMethodError using 'when' on mockito 1.6

5,792 views
Skip to first unread message

Colin

unread,
Dec 3, 2008, 5:56:14 PM12/3/08
to mockito
Hello,

I've just installed mockito-all-1.6 and I'm having trouble stubbing
with the new 'when' method. My environment is eclipse 3.3.2, junit
4.1, jre 1.6.0_04, XP.

My test method:
@Test
public void testListStubs() throws Exception {
List<String> mockList = mock(List.class);

when(mockList.get(0)).thenReturn("hello");
System.out.println("list 0: " + mockList.get(0));
}

When running the test it fails on the 'when' method call with this
error:

java.lang.NoSuchMethodError: org.mockito.Mockito.when(Ljava/lang/
Object;)Lorg/mockito/internal/progress/NewOngoingStubbing;
at com.lim.rdw.phases.process.MimDataRecordTest.testListStubs
(MimDataRecordTest.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:597)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody
(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected
(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod
(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run
(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod
(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run
(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected
(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected
(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run
(TestClassRunner.java:52)
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)

If I change 'when' to 'stub' and 'thenReturn' to 'toReturn' the same
test will run successfully under mockito 1.3.

All suggestions appreciated.

thanks,
Colin

szczepiq

unread,
Dec 4, 2008, 8:25:50 AM12/4/08
to moc...@googlegroups.com
Hi,

Please make sure you have only one version of mockito on the
classpath. Let me know this helps.

Cheers,
Szczepan Faber

Colin

unread,
Dec 4, 2008, 4:06:53 PM12/4/08
to mockito
Yes, that was the problem. Sigh.. years of working with Java and
still getting bitten by the classpath.

Thank you for the quick reply and all your work on this exceptional
tool.

-- Colin

On Dec 4, 2:25 am, szczepiq <szcze...@gmail.com> wrote:
> Hi,
>
> Please make sure you have only one version of mockito on the
> classpath. Let me know this helps.
>
> Cheers,
> Szczepan Faber
>

szczepiq

unread,
Dec 4, 2008, 6:27:22 PM12/4/08
to moc...@googlegroups.com
No worries.

Thanks!
Szczepan Faber
Reply all
Reply to author
Forward
0 new messages