You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Xiao Wang (Jira)" <ji...@apache.org> on 2021/09/22 03:39:00 UTC
[jira] [Created] (CODEC-303) Refactor NoOpBaseNCodec to improve
test logic
Xiao Wang created CODEC-303:
-------------------------------
Summary: Refactor NoOpBaseNCodec to improve test logic
Key: CODEC-303
URL: https://issues.apache.org/jira/browse/CODEC-303
Project: Commons Codec
Issue Type: Improvement
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class [NoOpBaseNCodec|https://github.com/apache/commons-codec/blob/b70e177f8733e9dd4e5f503620ed0b136b74785b/src/test/java/org/apache/commons/codec/binary/BaseNCodecTest.java#L375] extends production class [BaseNCodec|https://github.com/apache/commons-codec/blob/b70e177f8733e9dd4e5f503620ed0b136b74785b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java#L51] to assist testing [BaseNCodec.ensureBufferSize(int, Context)|https://github.com/apache/commons-codec/blob/b70e177f8733e9dd4e5f503620ed0b136b74785b/src/main/java/org/apache/commons/codec/binary/BaseNCodec.java#L570]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
h3. Current Implementation
* {{NoOpBaseNCodec}} extends {{BaseNCodec}} and call super constructor with fixed parameters.
* {{NoOpBaseNCodec}} implements three abstract methods defined in parent class.
h3. Proposed Implementation
* Replace {{NoOpBaseNCodec}} with a mocking object created by Mockito.
* No need to implement the abstract methods as they will donothing by default.
* Create a method to return the mocking object for reusing.
h3. Motivation
* Decouple test class {{NoOpBaseNCodec}} from production interface {{BaseNCodec}}.
* Remove the redundant overridden methods.
* Make testing logic more explict.
h3. More Thought
* We can get rid of the method that return the mocking object and directly create the mocking object inside of the test case.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)