funbee / mockito

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

Verfication of varArgs call yields NPE #13

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Try to run the following test case:

package com.gu.r2.perftest.cifurlmapper;

import org.junit.Test;
import org.mockito.Mockito;

public class MockitoTest {

    @Test
    public void shouldWork() {
        MyClass myClass = Mockito.mock(MyClass.class);
        myClass.varArgs("");        
        Mockito.verify(myClass).varArgs((String[]) Mockito.anyObject());

    }       
    public class MyClass {      
        public void varArgs(String... args) {

        }       
    }

}

What is the expected output? What do you see instead?
A passing testcase. An NPE:
java.lang.NullPointerException
    at java.lang.reflect.Array.getLength(Native Method)
    at
org.mockito.internal.matchers.ArrayEquals.createObjectArray(ArrayEquals.java:77)
    at
org.mockito.internal.invocation.Invocation.expandVarArgs(Invocation.java:57)
    at org.mockito.internal.invocation.Invocation.<init>(Invocation.java:46)
    at org.mockito.internal.MockHandler.intercept(MockHandler.java:65)
    at
org.mockito.internal.creation.MethodInterceptorFilter.intercept(MethodIntercepto
rFilter.java:49)
    at
com.gu.r2.perftest.cifurlmapper.MockitoTest$MyClass$$EnhancerByCGLIB$$237bdab6.v
arArgs(<generated>)
    at com.gu.r2.perftest.cifurlmapper.MockitoTest.shouldWork(MockitoTest.java:12)
    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:597)
    at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
    at org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
    at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
    at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadi
e.java:87)
    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:5
1)
    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(JUnit4TestReferen
ce.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.jav
a:196)

What version of the product are you using? On what operating system?
1.2

Please provide any additional information below.
When changing the signature to varArgs(String[] args) it works fine.

Best,
Felix

Original issue reported on code.google.com by felix.le...@gmail.com on 15 May 2008 at 5:47

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 17 May 2008 at 9:54

GoogleCodeExporter commented 9 years ago
Using the current version you can fix the problem by changing following:
Mockito.verify(myClass).varArgs((String[]) Mockito.anyObject());

Into this:
Mockito.verify(myClass).varArgs((String) Mockito.anyObject());

The bug is fixed in trunk.

Original comment by szcze...@gmail.com on 17 May 2008 at 12:24

GoogleCodeExporter commented 9 years ago

Original comment by szcze...@gmail.com on 19 Apr 2009 at 7:40

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 2 Dec 2012 at 10:21