@Test
public void popupRelevantRevertedOrder() throws IOException {

    try (PDDocument doc = PDFParser.parse(SeekableSources.inMemorySeekableSourceFrom(
            getClass().getClassLoader().getResourceAsStream("pdf/popup_annotation.pdf")))) {
        PDPage firstOrigin = doc.getPage(0);
        List<PDAnnotation> annots = firstOrigin.getAnnotations();
        Collections.reverse(annots);
        firstOrigin.setAnnotations(annots);
        PDPage firstNew = new PDPage();
        lookup.addLookupEntry(firstOrigin, firstNew);
        new AnnotationsDistiller(doc).retainRelevantAnnotations(lookup);
        List<PDAnnotation> annotations = firstNew.getAnnotations();
        assertFalse(annotations.isEmpty());
        List<PDAnnotationMarkup> parent = annotations.stream().filter(a -> a instanceof PDAnnotationPopup)
                .map(a -> ((PDAnnotationPopup) a).getParent()).collect(Collectors.toList());
        assertEquals(1, parent.size());
        assertTrue(annotations.contains(parent.get(0)));
    }
}