title: Mockito ExceptionInInitializer error with simple DAO
body: <p>I'm starting to use Mockito with Junit 4.12, Java EE, i need to test this service method in a CQRS program, i want to Mock the UserDAO (We are dealing with users) and then assert some properties.</p>
  <p>This is what i made so far:</p>
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class UserCommandServiceTest {
  
      @InjectMocks
      private UserCommandService userCommandService;
  
      @Mock
      private UserDAO userDAO;
  
      @Before
      public void init() {
  
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void testCreation() throws Exception {
          User test = new User();
          test.setUsername(&quot;test_username&quot;);
          Mockito.when(userDAO.findById(Mockito.anyInt())).thenReturn(test);
          assertEquals(0, 0);
  
      }
  
  }
  </code></pre>
  <p>The problem is not the test itself (as you can see there is an AssertEquals(0,0)), it is the fact that it just not run, it gives me <code>ExceptionInInitializer</code> when i mock the DAO, I don't know if it useful to post the DAO code, but it is just a simple CRUD class with JPA annotations.</p>
  <p>Here i post the full trace:</p>
  <pre><code>java.lang.ExceptionInInitializerError
      at org.mockito.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:167)
      at org.mockito.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
      at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:217)
      at org.mockito.cglib.core.KeyFactory$Generator.create(KeyFactory.java:145)
      at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:117)
      at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:109)
      at org.mockito.cglib.core.KeyFactory.create(KeyFactory.java:105)
      at org.mockito.cglib.proxy.Enhancer.&lt;clinit&gt;(Enhancer.java:70)
      at org.mockito.internal.creation.cglib.ClassImposterizer.createProxyClass(ClassImposterizer.java:95)
      at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:57)
      at org.mockito.internal.creation.cglib.ClassImposterizer.imposterise(ClassImposterizer.java:49)
      at org.mockito.internal.creation.cglib.CglibMockMaker.createMock(CglibMockMaker.java:24)
      at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:33)
      at org.mockito.internal.MockitoCore.mock(MockitoCore.java:59)
      at org.mockito.Mockito.mock(Mockito.java:1285)
      at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:33)
      at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16)
      at org.mockito.internal.configuration.DefaultAnnotationEngine.createMockFor(DefaultAnnotationEngine.java:43)
      at org.mockito.internal.configuration.DefaultAnnotationEngine.process(DefaultAnnotationEngine.java:66)
      at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:71)
      at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:55)
      at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:108)
      at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27)
      at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:276)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
      at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
  Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not &quot;opens java.lang&quot; to unnamed module @224edc67
      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
      at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
      at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
      at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
      at org.mockito.cglib.core.ReflectUtils$2.run(ReflectUtils.java:57)
      at java.base/java.security.AccessController.doPrivileged(AccessController.java:312)
      at org.mockito.cglib.core.ReflectUtils.&lt;clinit&gt;(ReflectUtils.java:47)
      ... 40 more
  </code></pre>
  <p>I'm working with mockito 1.10.19.</p>