ebean-orm-tools/ebean-idea-enhancer

Unable to mock Entity when plugin is enabled

pnartowski opened this issue · 6 comments

Hi

I'm unable to mock Entity, when running test getting :

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: class SimpleEntity

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.


Caused by: java.lang.ClassFormatError: Duplicate method name "_ebean_getMarker" with signature "()Ljava.lang.String;" in class file SimpleEntity$MockitoMock$1545927225
@Entity
public class SimpleEntity {}

public class SimpleTest {
   @Test
   public void testOne() {
      SimpleEntity mock = mock(SimpleEntity.class)
   }
}

Plugin version: ebean-idea-11.41.4
in previous version (don't remember which one ) this code doesn't cause exception

java.lang.NullPointerException
	at test.model.PersistentFile$MockitoMock$1216739959._ebean_get_mockitoInterceptor(Unknown Source)
	at test.model.PersistentFile$MockitoMock$1216739959._ebean_set_mockitoInterceptor(Unknown Source)
	at test.model.PersistentFile$MockitoMock$1216739959.setMockitoInterceptor(Unknown Source)
	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:49)
	at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
	at org.mockito.Mockito.mock(Mockito.java:1908)
	at org.mockito.Mockito.mock(Mockito.java:1817)
	at test.enhancement.MockEntityBeanTest.mockitoMock(MockEntityBeanTest.java:12)
	...

Fixed in 11.42.2 of ebean-agent ... which treats mockitoInterceptor field as a transient field.

I'll update and release this plugin with the updated agent. For people in more of a hurry.

- mkdir ~/.ebean
- download the ebean-agent-11.42.3.jar from maven central and put it into ~/.ebean
- turn the plugin off and then back on (this makes the plugin look for an agent in the ~/.ebean directory)
- Run the tests again (this time mockitoInterceptor field is not treated as a persistent field)

FYI The updated plugin has been submitted to Jetbrains. Should be available in approx 2 days.

Yeah cool. I'll keep pondering this and maybe come back to it some time later.

Cheers, Rob.