The first and simplest test is to check that a document has the same number of form fields as the referenced document:
@Test public void haveSameNumberOfFields() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; AssertThat.document(filenameTest) .and(filenameReference) .haveSameNumberOfFields() ; }
The next test checks that the number of fields and their names are equal in both PDF documents:
@Test public void haveSameFields_ByName() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; AssertThat.document(filenameTest) .and(filenameReference) .haveSameFieldsByName() ; }
And finally, you can compare the contents in form fields in two documents using the
method haveSameFieldsByValue()
.
Fields with the same name must have the same contents:
@Test public void haveSameFields_ByValue() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; AssertThat.document(filenameTest) .and(filenameReference) .haveSameFieldsByValue() ; }
Whitespaces are “normalized”, see chapter 13.5: “Whitespace Processing”. |
Multiple and different test methods can be concatenated in one test, but such a test is not recommended because it's hard to find a good name:
@Test public void compareManyItems() throws Exception { String filenameTest = "documentUnderTest.pdf"; String filenameReference = "reference.pdf"; AssertThat.document(filenameTest) .and(filenameReference) .haveSameAppearance() .haveSameText ; }