You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltaspike.apache.org by "Gerhard Petracek (JIRA)" <ji...@apache.org> on 2014/09/11 11:00:38 UTC
[jira] [Closed] (DELTASPIKE-707) AbstractMockManager does not
support interfaces mocked by mockito
[ https://issues.apache.org/jira/browse/DELTASPIKE-707?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gerhard Petracek closed DELTASPIKE-707.
---------------------------------------
> AbstractMockManager does not support interfaces mocked by mockito
> -----------------------------------------------------------------
>
> Key: DELTASPIKE-707
> URL: https://issues.apache.org/jira/browse/DELTASPIKE-707
> Project: DeltaSpike
> Issue Type: Bug
> Components: TestControl
> Affects Versions: 1.0.2
> Environment: Mockito 1.9.5
> JDK 1.7u51
> Reporter: Falko Modler
>
> Following the [manual|https://deltaspike.apache.org/test-control.html#mock-frameworks], I tried to mock {{EntitityManager}} in my test class:
> {noformat}
> @RunWith(CdiTestRunner.class)
> public class SomeTest {
> @Inject
> private DynamicMockManager mockManager;
> @Test
> public void mockitoMockAsCdiBean() {
> mockManager.addMock(Mockito.mock(EntityManager.class));
> [...]
> }
> }
> {noformat}
> Unfortunately this doesn't work as {{AbstractMockManager}} fails with:
> {noformat}
> 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)
> {noformat}
> Following (rather ugly) workaound fixes the problem:
> {noformat}
> @Typed(EntityManager.class)
> public static abstract class EntityManagerMockBase implements EntityManager {
> }
> {noformat}
> {noformat}
> mockManager.addMock(Mockito.mock(EntityManagerMockBase.class));
> {noformat}
> 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.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)