Uploaded image for project: 'DeltaSpike'
  1. DeltaSpike
  2. DELTASPIKE-707

AbstractMockManager does not support interfaces mocked by mockito

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Problem
    • 1.0.2
    • None
    • TestControl
    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            famod Falko Modler
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: