Error messages of PDFUnit provide detailed information to support bug fixing. And they are as clear and expressive as possible. A message for an incorrect page size demonstrates this intention:
Wrong page format in 'multiple-formats-on-individual-pages.pdf' on page 1. Expected: 'height=297.00, width=210.00 (as 'mm')', but was: 'height=209.90, width=297.04 (as 'mm')'.
The position of an error is marked by the double brackets <[
and ]>
.
To keep error messages readable, long values are shortened. The number of dropped characters
is indicated as a number in the text surrounded by '...
', e.g.:
The expected content does not match the JavaScript in 'javaScriptClock.pdf'. Expected: '//<[Thisfileco...41...dbyPDFUnit]>', but was: '//<[Constantsu...4969...);break;}}]>'.
PDFUnit comes with error message in German and English language. Write you wish to info[at]pdfunit.com if you need error messages in another language.
Error messages come from the files messages.properties
or
messages_LANGUAGE.properties
. Each message in these files has the format
key = value
. PDFUnit uses a classes as keys. So the term 'error number' should
be replaced by the term 'error key'.
When the validation exception is caught at runtime, the method getErrorKey()
can be used to return the key from the current error message:
@Test public void testErrorKey_hasText() throws Exception { try { String filename = PATH + "content/empty-pages.pdf"; AssertThat.document(filename) .restrictedTo(EVERY_PAGE) .hasText() ; } catch (PDFUnitValidationException e) { String expectedKey = "com.pdfunit.messages.TextAvailableMessage"; String actualKey = e.getErrorKey(); assertEquals(expectedKey, actualKey); } }
You can also pass the error key to a logging method.