Validator { static void validateAdjacency(Document[] manifests) throws PDUStitchingException { int[] startOffsets = new int[manifests.length]; int[] endOffsets = new int[manifests.length]; for (int k = 0; k < manifests.length; k++) { Document manifest = manifests[k]; final NodeList nadirImageSizes = manifest.getElementsByTagName("slstr:nadirImageSize"); for (int i = 0; i < nadirImageSizes.getLength(); i++) { final Node nadirImageSize = nadirImageSizes.item(i); final Node grid = nadirImageSize.getAttributes().getNamedItem("grid"); startOffsets[k] = -1; endOffsets[k] = -1; if (grid != null && grid.getNodeValue().equals("Tie Points")) { final NodeList childNodes = nadirImageSize.getChildNodes(); for (int j = 0; j < childNodes.getLength(); j++) { if (childNodes.item(j).getNodeName().equals("sentinel3:startOffset")) { startOffsets[k] = Integer.parseInt(childNodes.item(j).getTextContent()); } else if (childNodes.item(j).getNodeName().equals("sentinel3:rows")) { endOffsets[k] = startOffsets[k] + Integer.parseInt(childNodes.item(j).getTextContent()); } } break; } } } Arrays.sort(startOffsets); Arrays.sort(endOffsets); for (int i = 0; i < manifests.length - 1; i++) { if (endOffsets[i] != -1 && startOffsets[i + 1] != -1 && endOffsets[i] != startOffsets[i + 1]) { throw new PDUStitchingException("Selected units must be adjacent"); } } }  static void validate(File[] manifestFiles);  }
@Test public void testAdjacency_notAdjacent() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { final File firstSlstrFile = TestUtils.getFirstSlstrFile(); final File thirdSlstrFile = TestUtils.getThirdSlstrFile(); Document[] manifests = new Document[2]; manifests[0] = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(firstSlstrFile); manifests[1] = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(thirdSlstrFile); try { Validator.validateAdjacency(manifests); fail("Exception expected"); } catch (PDUStitchingException e) { assertEquals("Selected units must be adjacent", e.getMessage()); } }