You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Xiao Wang (Jira)" <ji...@apache.org> on 2021/09/24 23:32:00 UTC

[jira] [Created] (PDFBOX-5284) Refactor PDFTabulaTextStripper to improve test design

Xiao Wang created PDFBOX-5284:
---------------------------------

             Summary: Refactor PDFTabulaTextStripper to improve test design
                 Key: PDFBOX-5284
                 URL: https://issues.apache.org/jira/browse/PDFBOX-5284
             Project: PDFBox
          Issue Type: Improvement
            Reporter: Xiao Wang


h3. Description

I noticed that there is a test class [PDFTabulaTextStripper|https://github.com/apache/pdfbox/blob/588cb208653262ada43732a4e61c6fa3158f45f4/pdfbox/src/test/java/org/apache/pdfbox/text/TestTextStripper.java#L619] extends production class [PDFTextStripper|https://github.com/apache/pdfbox/blob/588cb208653262ada43732a4e61c6fa3158f45f4/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java#L61] to assist testing  [PDFTextStripper.writeText(PDDocument, Writer)|https://github.com/apache/pdfbox/blob/588cb208653262ada43732a4e61c6fa3158f45f4/pdfbox/src/main/java/org/apache/pdfbox/text/PDFTextStripper.java#L222]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.

h3. Current Implementation
 * {{PDFTabulaTextStripper}} overrides {{computeFontHeight(PDFont)}} to control the behavior.
 * {{PDFTabulaTextStripper}} overrides default constructor to make sure the constructor do nothing.

h3. Proposed Implementation
 * Replace {{PDFTabulaTextStripper}} with a spying object created by Mockito.
 * Use method stub to control the behavior of default constructor {{computeFontHeight(PDFont)}}.
 * Create a method to return the mocking object for reusing.

h3. Motivation
 * Decouple test class {{PDFTabulaTextStripper}} from production class {{PDFTextStripper}}.
 * Remove the redundant test child class {{PDFTabulaTextStripper}}
 * Remove the redundant constructor.




--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org