Home > Back-end >  Cannot mock aem core component with Mockito 3.8
Cannot mock aem core component with Mockito 3.8

Time:09-22

I'm trying to mock a Teaser class (public interface) using mockito core 3.8 and I'm not able to do it.

I've JAVA 11 and this is the following error:

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: interface com.adobe.cq.wcm.core.components.models.Teaser.

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.12 8-LTS-237
JVM name           : Java HotSpot(TM) 64-Bit Server VM
JVM version        : 11.0.12 8-LTS-237
JVM info           : mixed mode
OS name            : Windows 10
OS version         : 10.0


Underlying exception : java.lang.IllegalStateException: Type not found: com.adobe.cq.wcm.core.components.internal.jackson.ComponentDataModelSerializer

What's happening here?

CodePudding user response:

I finally got a solution for this. The problem was that I didn't had wcm core components dependency on my project. Since AEMaaCS includes that dependency as a package, we didn't need to include the dependency in our project.

I ended up adding the dependency but just for the scope=test.

  • Related