dhamini-poornachandra / mockito

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

org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class org.apache.commons.net.ftp.FTPSClient$$EnhancerByMockitoWithCGLIB$$9780074c Mockito can only mock visible & non-final classes. #329

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. mockFtpsClient = mock(org.apache.commons.net.ftp.FTPSClient.class)
2. Mockito.doThrow(new RuntimeException("sftp 
error")).when(mockFtpsClient).connect(Matchers.<InetAddress>anyObject(),Matchers
.<Integer>anyObject());

What is the expected output? What do you see instead?
RuntimeException with msg "sftp error"

What version of the product are you using? On what operating system?
Mac OS 10.6.8

Please provide any additional information below.

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class 
org.apache.commons.net.ftp.FTPSClient$$EnhancerByMockitoWithCGLIB$$6ae4f533
Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing 
list.
    at com.rackspace.cloud.billing.nova.ftps.FTPSClientImplTest.setup(FTPSClientImplTest.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:129)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:296)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:102)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:42)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.mockito.cglib.core.CodeGenerationException: 
java.lang.reflect.InvocationTargetException-->null
    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
    at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
    at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
    at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:93)
    at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:50)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:52)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:41)
    at org.mockito.Mockito.spy(Mockito.java:1092)
    ... 29 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385)
    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220)
    ... 36 more
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class 
file 
org/apache/commons/net/ftp/FTPSClient$$EnhancerByMockitoWithCGLIB$$6ae4f533$$Enh
ancerByMockitoWithCGLIB$$fbfa4e90
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    ... 42 more

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class 
org.apache.commons.net.ftp.FTPSClient$$EnhancerByMockitoWithCGLIB$$6ae4f533
Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing 
list.
    at com.rackspace.cloud.billing.nova.ftps.FTPSClientImplTest.setup(FTPSClientImplTest.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:129)
    at org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.executeTest(PowerMockJUnit44RunnerDelegateImpl.java:296)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:102)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:42)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:71)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:199)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:62)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: org.mockito.cglib.core.CodeGenerationException: 
java.lang.reflect.InvocationTargetException-->null
    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
    at org.mockito.cglib.proxy.Enhancer.createHelper(Enhancer.java:378)
    at org.mockito.cglib.proxy.Enhancer.createClass(Enhancer.java:318)
    at org.mockito.internal.creation.jmock.ClassImposterizer.createProxyClass(ClassImposterizer.java:93)
    at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:50)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:52)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:41)
    at org.mockito.Mockito.spy(Mockito.java:1092)
    ... 29 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at org.mockito.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:385)
    at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:220)
    ... 36 more
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class 
file 
org/apache/commons/net/ftp/FTPSClient$$EnhancerByMockitoWithCGLIB$$6ae4f533$$Enh
ancerByMockitoWithCGLIB$$fbfa4e90_2
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
    ... 42 more

Original issue reported on code.google.com by venkyn...@gmail.com on 20 Mar 2012 at 8:00

GoogleCodeExporter commented 8 years ago
Hey,

Looks like some bug with cglib or on the junction between cglib and mockito.

Feel free to contribute a fix :)

Original comment by szcze...@gmail.com on 21 Mar 2012 at 3:39

GoogleCodeExporter commented 8 years ago
I have the same issue with an interface I am trying to mock. Using JDK7 though 
-- I wonder if that is the problem.

Original comment by rocketra...@gmail.com on 24 Mar 2012 at 3:47

GoogleCodeExporter commented 8 years ago
@rocketraman Could you make a simple testcase ?

Original comment by brice.du...@gmail.com on 24 Mar 2012 at 9:27

GoogleCodeExporter commented 8 years ago
The issue is resolved. thats a simple mistake from my side. 
After I changed from Matchers.<Integer>anyObject to Matchers.anyInt(), the 
exception disappeared.

Original comment by venkyn...@gmail.com on 25 Mar 2012 at 1:12

GoogleCodeExporter commented 8 years ago
Unfortunately the issue I am having is not that simple (as far as I can tell!), 
but so far I cannot reproduce it in a simple test case.

Original comment by rocketra...@gmail.com on 25 Mar 2012 at 1:24

GoogleCodeExporter commented 8 years ago
@rocketraman When you can reproduce it could you fill a new issue?

@venkynary This might be the junction with Powermock too. As the runner in 
PowerMock instantiate the test in their own classloader.

Original comment by brice.du...@gmail.com on 25 Mar 2012 at 7:56

GoogleCodeExporter commented 8 years ago
Marking this issue as invalid as nobody could actually show a reproducible 
code. A new issue shall be created with a proper test will be required if this 
issue appears again.

Original comment by brice.du...@gmail.com on 4 Dec 2013 at 3:48