NoClassDefFoundError for class MockitoInvocationHandler

I am using mockito-all-1.9.5-rc1.jar and powermock-mockito-1.4.12-full.jar . When I run this simple unit test for a mocking final method in a non-finite class.

 import static org.junit.Assert.assertEquals; import org.junit.Test; import org.junit.runner.RunWith; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) @PrepareForTest(ABC.class) public class ABCTest { @Test public void finalCouldBeMock() { final ABC abc = PowerMockito.mock(ABC.class); PowerMockito.when(abc.myMethod()).thenReturn("toto"); assertEquals("toto", abc.myMethod()); } } 

When I ran it, I got java.lang.NoClassDefFoundError: org/mockito/internal/MockitoInvocationHandler Caused by: java.lang.ClassNotFoundException: org.mockito.internal.MockitoInvocationHandler

When I search for fo class MockitoInvocationHandler in mockito-all-1.9.5-rc1.jar and powermock-mockito-1.4.12-full.jar . I could not find. Need help solving this problem! Thanks you

+7
source share
1 answer

Mockito 1.9.5-rc1 had to be reorganized internally to allow a third-party manufacturer. MockitoInvocationHandler was part of the internal components of Mockito (as the name of the package suggests) prior to version Mockito 1.9.0.

Due to these current changes, some earlier versions of Powermock releases are not compatible with the latest version of Mockito to date.

Another reason to avoid bullying / final finals or statics;)

Hope this helps Cheers,

+15
source

All Articles