How to Work Out the Error Message "Mockito cannot mock this class: class com.adobe.aemfd.docmanager.Document" | Community
Skip to main content
October 16, 2025
Question

How to Work Out the Error Message "Mockito cannot mock this class: class com.adobe.aemfd.docmanager.Document"

  • October 16, 2025
  • 1 reply
  • 316 views

When I work on the watermark processing test in the following codes:

 

Document mergedDoc = mock(Document.class);

Document mockOutDoc = mock(Document.class);

Document ddxDocMock = mock(Document.class);

 

based on the following pom.xml:

 

<!-- Testing -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>4.6.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit-addons</groupId>
<artifactId>junit-addons</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.wcm</groupId>
<artifactId>io.wcm.testing.aem-mock.junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.testing.caconfig-mock-plugin</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.adobe.cq</groupId>
<artifactId>core.wcm.components.testing.aem-mock-plugin</artifactId>
<scope>test</scope>
</dependency>

 

The following error message occurs:

 

org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.adobe.aemfd.docmanager.Document.

 

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


Java : 11
JVM vendor name : Oracle Corporation
JVM vendor version : 11.0.28+12-LTS-279
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 11.0.28+12-LTS-279
JVM info : mixed mode
OS name : Windows 10
OS version : 10.0


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 : java.lang.IllegalArgumentException: Could not create type

 

Are there any resolutions for me to make further modifications on adding the most appropriate dependency to get rid of the above error message?  Thanks.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

muskaanchandwani
Adobe Employee
Adobe Employee
October 24, 2025

Hello @yeouluen0929 
Could you try to -
1. Add (or verify) src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker with content:
mock-maker-inline
2. Use the same version for both mockito-core and mockito-inline