Compare the number of attachments in two documents:
@Test public void haveSameNumberOfEmbeddedFiles() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; AssertThat.document(filenameTest) .and(filenameReference) .haveSameNumberOfEmbeddedFiles() ; }
There is a parameterized test method to compare the attachments by name or by content:
@Test public void haveSameEmbeddedFiles() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; AssertThat.document(filenameTest) .and(filenameReference) .haveSameEmbeddedFiles(COMPARED_BY_NAME) .haveSameEmbeddedFiles(COMPARED_BY_CONTENT) ; }
The two constants are defined in com.pdfunit.Constants
:
// Constants defining the kind comparing embedded files:
com.pdfunit.Constants.COMPARED_BY_CONTENT
com.pdfunit.Constants.COMPARED_BY_NAME
You can use the utility ExtractEmbeddedFiles
to extract the attachments.
See chapter 9.4: “Extract Attachments”.