qdrzwd / dexmaker

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

[Mockito]: NoClassDefFoundError when mocking throwing an exception #17

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
*NOTE*: This is a parallel submission for Mockito's one, located at 
http://code.google.com/p/mockito/issues/detail?id=386 - note that there is a 
workaround in the comments there.

What steps will reproduce the problem?
1. Add mockito, dexmaker and dexmaker-mockito to project
2. Create a mock for SomeClass (code provided in additional information)
3. Instruct to throw SomeException when calling doSomething() method
4. Call doSomething() method

What is the expected output? What do you see instead?
Expected:
Exception is to be thrown

Instead:
Exception is thrown:
java.lang.NoClassDefFoundError: sun.reflect.ReflectionFactory
at 
org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflec
tionFactoryInstantiator.java:24)
at 
org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiator
Strategy.java:65)
at org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:76)
at org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:59)
at org.objenesis.ObjenesisHelper.newInstance(ObjenesisHelper.java:28)
at 
org.mockito.internal.stubbing.answers.ThrowsExceptionClass.answer(ThrowsExceptio
nClass.java:27)
at 
org.mockito.internal.stubbing.StubbedInvocationMatcher.answer(StubbedInvocationM
atcher.java:34)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:91)
at 
org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:2
9)
at 
org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifier
Handler.java:38)
at 
com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAda
pter.java:54)
at SomeClass_Proxy.doSomething(SomeClass_Proxy.generated)
at 
com.example.SomeTestCase.testDoSomethingSomeExceptionThrown(SomeTestCase.java:10
8)
at java.lang.reflect.Method.invokeNative(Native Method)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at 
android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:53
7)
at 
android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)

What version of the product are you using? On what operating system?
Mockito 1.9.5 (mockito-all version)
dexmaker 0.9
Android 4.0.1 (emulator)
JUnit3

Please provide any additional information below.
0. You guys did great job by providing Mockito to Android developers. I love it!
1. Mocking value returns and verification of methods running appears to be 
working fine.
2. Some code:
public class SomeClass {
    public void doSomething() throws SomeException {

    }

}

public class SomeException extends Exception {

    /**
     * 
     */
    private static final long serialVersionUID = 1544471714051523296L;

}

public class SomeTestCase extends TestCase {
    public void testSendAsyncMessageMessageNotSentException() {
        SomeClass someClass = Mockito.mock(SomeClass.class);

        try {
            Mockito.doThrow(SomeException.class).when(someClass).doSomething();
            someClass.doSomething();
            fail();
        } catch (SomeException e1) {
            //success
        } catch (Exception e) {
            fail();
        }
    }
}

Original issue reported on code.google.com by tomasz.p...@gmail.com on 23 Oct 2012 at 10:46

GoogleCodeExporter commented 8 years ago
Please use dexmaker 1.0.

Original comment by limpbizkit on 10 Feb 2013 at 11:56

GoogleCodeExporter commented 8 years ago
I'm using dexmaker-1.0 but the same problem is reproduced.

Used libraries are:
- mockito-all-1.9.5.jar
- dexmaker-1.0.jar
- dexmaker-mockito-1.0.jar

Original comment by jun.nama@gmail.com on 25 Sep 2013 at 12:23