Source:
static void validateMultipageReceiptData(List<RecognizedForm> recognizedReceipts) { assertEquals(3, recognizedReceipts.size()); RecognizedForm receiptPage1 = recognizedReceipts.get(0); RecognizedForm receiptPage2 = recognizedReceipts.get(1); RecognizedForm receiptPage3 = recognizedReceipts.get(2); assertEquals(1, receiptPage1.getPageRange().getFirstPageNumber()); assertEquals(1, receiptPage1.getPageRange().getLastPageNumber()); Map<String, FormField> receiptPage1Fields = receiptPage1.getFields(); assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, receiptPage1Fields.get("MerchantAddress") .getValue().asString()); assertEquals("Bilbo Baggins", receiptPage1Fields.get("MerchantName") .getValue().asString()); assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, receiptPage1Fields.get("MerchantPhoneNumber") .getValue().asPhoneNumber()); assertNotNull(receiptPage1.getPages()); assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage1Fields.get("ReceiptType").getValue().asString()); assertEquals(0, receiptPage2.getFields().size()); List<FormPage> receipt2Pages = receiptPage2.getPages(); assertEquals(1, receipt2Pages.size()); assertNull(receipt2Pages.stream().findFirst().get().getLines()); assertEquals(2, receiptPage2.getPageRange().getFirstPageNumber()); assertEquals(2, receiptPage2.getPageRange().getLastPageNumber()); assertEquals(3, receiptPage3.getPageRange().getFirstPageNumber()); assertEquals(3, receiptPage3.getPageRange().getLastPageNumber()); Map<String, FormField> receiptPage3Fields = receiptPage3.getFields(); assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, receiptPage3Fields.get("MerchantAddress").getValue().asString()); assertEquals("Frodo Baggins", receiptPage3Fields.get("MerchantName").getValue().asString()); assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, receiptPage3Fields.get("MerchantPhoneNumber").getValue().asPhoneNumber()); assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage3Fields.get("ReceiptType").getValue().asString()); }

Target:
static void validateMultipageReceiptData(List<RecognizedForm> recognizedReceipts) { assertEquals(3, recognizedReceipts.size()); RecognizedForm receiptPage1 = recognizedReceipts.get(0); RecognizedForm receiptPage2 = recognizedReceipts.get(1); RecognizedForm receiptPage3 = recognizedReceipts.get(2); assertEquals(1, receiptPage1.getPageRange().getFirstPageNumber()); assertEquals(1, receiptPage1.getPageRange().getLastPageNumber()); Map<String, FormField> receiptPage1Fields = receiptPage1.getFields(); assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, receiptPage1Fields.get("MerchantAddress") .getValue().asString()); assertEquals("Bilbo Baggins", receiptPage1Fields.get("MerchantName") .getValue().asString()); assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, receiptPage1Fields.get("MerchantPhoneNumber") .getValue().asPhoneNumber()); assertNotNull(receiptPage1.getPages()); assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage1Fields.get("ReceiptType").getValue().asString()); assertEquals(0, receiptPage2.getFields().size()); List<FormPage> receipt2Pages = receiptPage2.getPages(); assertEquals(1, receipt2Pages.size()); assertEquals(0, receipt2Pages.stream().findFirst().get().getLines().size()); assertEquals(2, receiptPage2.getPageRange().getFirstPageNumber()); assertEquals(2, receiptPage2.getPageRange().getLastPageNumber()); assertEquals(3, receiptPage3.getPageRange().getFirstPageNumber()); assertEquals(3, receiptPage3.getPageRange().getLastPageNumber()); Map<String, FormField> receiptPage3Fields = receiptPage3.getFields(); assertEquals(EXPECTED_MULTIPAGE_ADDRESS_VALUE, receiptPage3Fields.get("MerchantAddress").getValue().asString()); assertEquals("Frodo Baggins", receiptPage3Fields.get("MerchantName").getValue().asString()); assertEquals(EXPECTED_MULTIPAGE_PHONE_NUMBER_VALUE, receiptPage3Fields.get("MerchantPhoneNumber").getValue().asPhoneNumber()); assertEquals(ITEMIZED_RECEIPT_VALUE, receiptPage3Fields.get("ReceiptType").getValue().asString()); }