freepascal / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

spy() trows StringIndexOutOfBoundsException when called on an anonymous inner class #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
As per subject :)

This is the trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: 1
    at java.lang.String.substring(String.java:1765)
    at org.mockito.internal.util.MockUtil.toInstanceName(MockUtil.java:33)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:22)
    at org.mockito.Mockito.spy(Mockito.java:500)
    at com.acme.secretproject.TestRetry.testRetrySuccess(TestRetry.java:21)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestR
eference.java:130)
    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.jav
a:196)

This is how to reproduce, I instantiate an anonymous implementation of the
interface java.util.concurrent.Callable, the Class.getSimpleName() returns
an empty string... and makes mockito to break :

   public void testRetrySuccess() throws Exception  {
        final Object expected = new Object(); 
        Callable<Object> successLogic = new Callable<Object>() {
            public Object call() throws Exception {
                return expected;
            }
        };

        Callable<Object> spy = spy(successLogic);
        ...
   }

Thanks guys! Fantastic framework.

Original issue reported on code.google.com by luigi.vi...@gmail.com on 7 Nov 2008 at 2:44

GoogleCodeExporter commented 9 years ago
ups sorry, this is duplicate of bug #29. please ignore this.

Original comment by luigi.vi...@gmail.com on 7 Nov 2008 at 2:45

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 12 Nov 2008 at 11:24

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 14 Jan 2009 at 10:48