Free Support Forum -

Mocking Document with JUnit / Mockito | Aspose.Words for Java | Avoid Illegal Argument Exception

Hello Aspose Team,

Is there any possibility to mock the Document object using Junit/Mokito?
Something like

public void processFileValid() throws Exception {
	Document mockMainDoc = Mockito.mock(Document.class);

	 String processFile = cerAsposeService.processFile(mockMainDoc);

I am getting Exception when i use the above code :

java.lang.IllegalArgumentException: Specified argument was out of the range of valid values.Parameter name: sectionIdx
at com.aspose.words.DocumentBuilder.zzO(Unknown Source)
at com.aspose.words.DocumentBuilder.moveToDocumentStart(Unknown Source)
at com.aspose.words.DocumentBuilder.setDocument(Unknown Source)
at com.aspose.words.DocumentBuilder.<init>(Unknown Source)

Please do let me know if there are other alternatives.


We have logged your requirement/problem in our issue tracking system. Your ticket number is WORDSJAVA-2531. We will further look into the details of this and will keep you updated here on the status of this ticket.


It seems that you are working with an empty, null or uninitialized Document object. Can you please provide your full test code here for our reference? It would be great if you please first check the code as is (without Mock).