Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot mock some models with mockito after upgrade #2891

Open
arungm20 opened this issue Nov 7, 2024 · 0 comments
Open

Cannot mock some models with mockito after upgrade #2891

arungm20 opened this issue Nov 7, 2024 · 0 comments

Comments

@arungm20
Copy link

arungm20 commented Nov 7, 2024

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

  • AEM as a Cloud Service SDK Version 2024.10.18459.20241031T210302Z-241000
  • Core Components version 2.22.12
  • JDK 11
  • Mockito core version: 5.2.0

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:

  • Compiled by older versions of scalac
  • Classes that are part of the Android distribution
    Caused by: java.lang.NoClassDefFoundError: Lcom/adobe/granite/toggle/api/ToggleRouter;
    Caused by: java.lang.ClassNotFoundException: com.adobe.granite.toggle.api.ToggleRouter
    `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant