adobe / aem-core-wcm-components

Standardized components to build websites with AEM.
https://docs.adobe.com/content/help/en/experience-manager-core-components/using/introduction.html
Apache License 2.0
746 stars 753 forks source link

Cannot mock some models with mockito after upgrade #2891

Open arungm20 opened 2 weeks ago

arungm20 commented 2 weeks ago

Bug Report

Current Behavior I'm not able to mock com.day.cq.wcm.foundation.model.responsivegrid.ResponsiveGrid and other models

Expected behavior/code A mocked version of the sling model.

Environment

Hello everyone, I'm trying to perform some unit testings but I'm not able to mock some core component classes after update to new version of AEM SDK 2024.10.18459.20241031T210302Z-241000

I am using @Mock private ResponsiveGrid responsiveGrid;

The error I'm getting is the following `org.mockito.exceptions.base.MockitoException:

Mockito cannot mock this class: class com.day.cq.wcm.foundation.model.responsivegrid.ResponsiveGrid.

If you're not sure why you're getting this error, please open an issue on GitHub.

Java : 11 JVM vendor name : Amazon.com Inc. JVM vendor version : 11.0.15+9-LTS JVM name : OpenJDK 64-Bit Server VM JVM version : 11.0.15+9-LTS JVM info : mixed mode OS name : Mac OS X OS version : 14.7

You are seeing this disclaimer because Mockito is configured to create inlined mocks. You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.

Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, interface org.apache.sling.api.adapter.Adaptable, class com.day.cq.wcm.foundation.model.responsivegrid.ResponsiveGrid, interface org.apache.sling.api.resource.Resource, class org.apache.sling.api.adapter.SlingAdaptable, interface com.day.cq.wcm.foundation.model.responsivegrid.export.ResponsiveGridExporter, class org.apache.sling.api.resource.AbstractResource] Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [class java.lang.Object, interface org.apache.sling.api.adapter.Adaptable, class com.day.cq.wcm.foundation.model.responsivegrid.ResponsiveGrid, interface org.apache.sling.api.resource.Resource, class org.apache.sling.api.adapter.SlingAdaptable, interface com.day.cq.wcm.foundation.model.responsivegrid.export.ResponsiveGridExporter, class org.apache.sling.api.resource.AbstractResource] Caused by: java.lang.IllegalStateException:

Byte Buddy could not instrument all classes within the mock's type hierarchy

This problem should never occur for javac-compiled classes. This problem has been observed for classes that are: