ebean-orm-tools / ebean-idea-enhancer

Ebean enhancer for IntelliJ Idea that uses javaagent
Apache License 2.0
1 stars 0 forks source link

Unable to mock Entity when plugin is enabled #8

Open DaniSalasDev opened 1 year ago

DaniSalasDev commented 1 year ago

Refer https://github.com/ebean-orm-tools/ebean-idea-enhancer/issues/2

IntelliJ IDEA 2022.2 (Community Edition) Ebean enhancer 13.6.1

Log trace:

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.

Java               : 11
JVM vendor name    : Oracle Corporation
JVM vendor version : 11.0.2+9
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 11.0.2+9
JVM info           : mixed mode
OS name            : Windows 10
OS version         : 10.0

Underlying exception : java.lang.IllegalStateException: Error invoking (accesor)::defineClass
[...]
Caused by: java.lang.ClassFormatError: Duplicate method name "_ebean_getMarker" with signature "()Ljava.lang.String;" in class file
@Entity
public class SimpleEntity {}

public class SimpleTest {
   @Test
   public void testOne() {
      SimpleEntity mock = mock(SimpleEntity.class)
   }
}
rbygrave commented 1 year ago

I can't reproduce this issue. See also test at: https://github.com/ebean-orm/ebean-agent/blob/master/test/src/test/java/test/enhancement/MockEntityBeanTest.java

Given the Duplicate method name "_ebean_getMarker" ... error that should not occur so there is something odd perhaps with the build time enhancement via maven or gradle? What is the build time enhancement you are using? Can you put up an example project that reproduces the issue? [or clone ebean-agent and reproduce via the MockEntityBeanTest?]

rbygrave commented 1 year ago

Also have a look at the ebean.mf synthetic: false option. That makes the code added via enhancement not synthetic and hence visible via byte code viewers. Given the Duplicate method name "_ebean_getMarker" we probably want to set synthetic: false so that we can look at the class in terms of byte code.

https://github.com/ebean-orm/ebean-agent/blob/master/test/src/test/resources/ebean.mf#L6

DaniSalasDev commented 1 year ago

That would be a legacy SBT project; I've extracted a sample project reproducing the issue:

https://github.com/DanPintas/ebean-enhancer-issue-8