dhamini-poornachandra / mockito

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

Verifying a method which returns a char fails #374

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

@RunWith(MockitoJUnitRunner.class)
public class TestClassTest {

    @Mock private TestInterface testInterface;
    @InjectMocks private TestClass testClass;

    @Test
    public void run_test() {
        testClass.runClass();
        verify(testInterface).runInterface();
    }
}

public class TestClass {

    private final TestInterface testInterface;

    public TestClass(TestInterface testInterface) {
        this.testInterface = testInterface;
    }
    public void runClass() {
        testInterface.runInterface();
    }
}

public interface TestInterface {
    char runInterface();
}

What is the expected output? What do you see instead?
The expected output is that the unit test should pass. Instead the following 
exception is thrown:

java.lang.ClassCastException: java.lang.Integer cannot be cast to 
java.lang.Character
    at TestInterface$$EnhancerByMockitoWithCGLIB$$7ad0e4f2.test(<generated>)
    at TestClassTest.run_test(TestClassTest.java:22)
    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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
    at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

What version of the product are you using? On what operating system?
Mockito 1.9.5-rc1
Windows 7 64bit

Please provide any additional information below.
If you change the return type of runInterface() to any other primitive then the 
test passes.

Original issue reported on code.google.com by shams.asari@gmail.com on 6 Sep 2012 at 3:15

GoogleCodeExporter commented 8 years ago
Already fixed in issue 352

Thanks for the report!

Original comment by brice.du...@gmail.com on 6 Sep 2012 at 3:38