Free Support Forum - aspose.com

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

@Test
public void processFileValid() throws Exception {
	
	Document mockMainDoc = Mockito.mock(Document.class);
	Mockito.when(mockMainDoc.save(Mockito.anyString())).thenReturn(null);

	 String processFile = cerAsposeService.processFile(mockMainDoc);
	Assert.assertNotNull(processFile);
}

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.

@sharma.vikash.mca,

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.

@sharma.vikash.mca,

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).