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

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

    [ https://issues.apache.org/jira/browse/PDFBOX-5284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17420100#comment-17420100 ] 

Tilman Hausherr commented on PDFBOX-5284:
-----------------------------------------

Thanks, but I don't see how this is an improvement in readability. The old code uses the class like an actual user (i.e. the Tabula project) would use it. The new code requires one to be familiar with Mockito. I also see the "risk" to have many future PRs wanting to use Mockito for every possible test.

I wouldn't mind having future tests with Mockito that increase our test coverage.

> 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
>            Priority: Minor
>
> 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