Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Not A Problem
-
1.0.2
-
None
-
None
-
Mockito 1.9.5
JDK 1.7u51
Description
Following the manual, I tried to mock EntitityManager in my test class:
@RunWith(CdiTestRunner.class) public class SomeTest { @Inject private DynamicMockManager mockManager; @Test public void mockitoMockAsCdiBean() { mockManager.addMock(Mockito.mock(EntityManager.class)); [...] } }
Unfortunately this doesn't work as AbstractMockManager fails with:
java.lang.IllegalArgumentException: $javax.persistence.EntityManager$$EnhancerByMockitoWithCGLIB$$b065dd9c isn't a supported approach for mocking -> please extend from the original class. at org.apache.deltaspike.testcontrol.impl.mock.AbstractMockManager.addMock(AbstractMockManager.java:45)
Following (rather ugly) workaound fixes the problem:
@Typed(EntityManager.class) public static abstract class EntityManagerMockBase implements EntityManager { }
mockManager.addMock(Mockito.mock(EntityManagerMockBase.class));
If this problem cannot be solved then the documentation should at least mention that mocking does not work for interfaces and how to work around that.