easyforgood / mockito

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

NoClassDefFoundError when attempting to mock particular interfaces #446

Open GoogleCodeExporter opened 8 years ago

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

When attempting to mock certain interfaces in my project I am receiving 
NoClassDefFoundError. Many other mocks in the same project are working. I am 
wondering if there is a known issue with mocking interfaces that causes this 
error.

What is the expected output? What do you see instead?

I expect a successful mock, but I instead receive NoClassDefFoundError.

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

I am using Mockito 1.9.5 on Windows 7.

Please provide any additional information below.

I have included a failure trace from a unit test that attempts to mock an 
interface called IContributor:

java.lang.NoClassDefFoundError: 
com.ibm.team.repository.common.IContributor$$EnhancerByMockitoWithCGLIB$$2d3e1bb
2 (initialization failure)
    at java.lang.J9VMInternals.initialize(J9VMInternals.java:140)
    at sun.reflect.GeneratedSerializationConstructorAccessor13.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:527)
    at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:40)
    at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
    at org.mockito.internal.creation.jmock.ClassImposterizer.createProxy(ClassImposterizer.java:128)
    at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:63)
    at org.mockito.internal.creation.jmock.ClassImposterizer.imposterise(ClassImposterizer.java:56)
    at org.mockito.internal.creation.CglibMockMaker.createMock(CglibMockMaker.java:23)
    at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:26)
    at org.mockito.internal.MockitoCore.mock(MockitoCore.java:51)
    at org.mockito.Mockito.mock(Mockito.java:1243)
    at org.mockito.Mockito.mock(Mockito.java:1120)
    at jazzhubunittesting.UtilityServiceTest.testGetProjectUuids(UtilityServiceTest.java:513)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
    at java.lang.reflect.Method.invoke(Method.java:611)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    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)

Original issue reported on code.google.com by hlb...@bucknell.edu on 30 Jul 2013 at 6:30

GoogleCodeExporter commented 8 years ago
That's weird it seems related to the fact that you are using J9, as I don't 
have access to J9, could you try some basic tests
 - simple mock with your own interface
 - simple mock using IContributor or something else on the classpath

I wonder do your code runs in an OSGI environment ? Do this code works when run 
outside of Eclipse ?

Original comment by brice.du...@gmail.com on 4 Dec 2013 at 2:16