content: package pdfact.core;
  
  import static org.junit.Assert.assertEquals;
  import org.junit.BeforeClass;
  import org.junit.Test;
  import pdfact.core.model.Document;
  import pdfact.core.model.Paragraph;
  import pdfact.core.model.Position;
  import pdfact.core.model.SemanticRole;
  import pdfact.core.pipes.PlainPdfActCorePipe;
  import pdfact.core.util.exception.PdfActException;
  
  /**
   * A class that tests the extraction results of PdfAct for PDF file "PDF0007".
   */
  public class TestPdf0007 {
    /**
     * The PDF document to examine in this test.
     */
    protected static Document doc;
  
    /**
     * Parses the PDF document.
     */
    @BeforeClass
    public static void setup() throws PdfActException {
      doc = new Document("src/test/resources/pdfs/PDF0007_sample_pdf_with_ligatures_and_diacritics_2021.pdf");
      doc = new PlainPdfActCorePipe().execute(doc);
    }
  
    /**
     * Returns the text of the <blockNum>-th paragraph on the <pageNum>-th page as a string. Note that
     * blockNum is 0-based and pageNum is 1-based.
     */
    protected Paragraph getParagraph(int pageNum, int paragraphNum) {
      int prevParagraphPageNum = -1;
      int currentParagraphIndex = -1;
      for (Paragraph paragraph : doc.getParagraphs()) {
        Position pos = paragraph.getFirstPosition();
        if (prevParagraphPageNum != pos.getPageNumber()) {
          currentParagraphIndex = 0;
        }
        if (pos.getPageNumber() == pageNum && currentParagraphIndex == paragraphNum) {
          return paragraph;
        }
        if (pageNum < pos.getPageNumber()) {
          return null;
        }
        prevParagraphPageNum = pos.getPageNumber();
        currentParagraphIndex++;
      }
      return null;
    }
  
    /**
     * Tests the extraction results on the level of paragraphs.
     */
    @Test
    public void testExtractPage01Paragraph00() {
      Paragraph paragraph = getParagraph(1, 0);
  
      String expectedText = "This is not a tutorial on how to make crème brûlée efficiently and "
        + "accurately. Instead, this is a sample PDF with some ligatures like fi, fl and ffi and "
        + "some characters with diacritical marks like ü, š, õ or å created to see if PdfAct is "
        + "able to extract such characters accurately.";
      SemanticRole expectedRole = SemanticRole.BODY_TEXT;
  
      assertEquals(expectedText, paragraph.getText());
      assertEquals(expectedRole, paragraph.getSemanticRole());
    }
  
      /**
     * Tests the extraction results on the level of paragraphs.
     */
    @Test
    public void testExtractPage01Paragraph01() {
      Paragraph paragraph = getParagraph(1, 1);
  
      String expectedText = "1";
      SemanticRole expectedRole = SemanticRole.PAGE_FOOTER;
  
      assertEquals(expectedText, paragraph.getText());
      assertEquals(expectedRole, paragraph.getSemanticRole());
    }
  }
  