You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Xiao Wang (Jira)" <ji...@apache.org> on 2021/08/02 02:52:00 UTC
[jira] [Created] (JCR-4710) Refactor DummyInternalVersion in
VersionIteratorImplTest.java to improve test logic
Xiao Wang created JCR-4710:
------------------------------
Summary: Refactor DummyInternalVersion in VersionIteratorImplTest.java to improve test logic
Key: JCR-4710
URL: https://issues.apache.org/jira/browse/JCR-4710
Project: Jackrabbit Content Repository
Issue Type: Improvement
Components: jackrabbit-core
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class [DummyInternalVersion|https://github.com/apache/jackrabbit/blob/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/version/VersionIteratorImplTest.java#L32] implements a production interface [InternalVersion|https://github.com/apache/jackrabbit/blob/6ed753e4dc30b70fd2ba03ba1977e5d63c8d85dc/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/InternalVersion.java#L29] to assist testing production constructor [VersionIteratorImpl::VersionIteratorImpl(Session, InternalVersion)|https://github.com/apache/jackrabbit/blob/6ed753e4dc30b70fd2ba03ba1977e5d63c8d85dc/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/version/VersionIteratorImpl.java#L70]. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.
h3. Current Implementation
* {{DummyInternalVersion}} implements {{InternalVersion}}, creates two variables id and successors to control the behavior of method {{getId()}} and {{getSuccessors()}}.
* Impelements other redundant methods and make them return null.
h3. Proposed Implementation
* Replace {{DummyInternalVersion}} with a mocking object created by Mockito.
* Use method stub to control the behavior of {{getId()}} and {{getSuccessors()}} in the mocking object.
* Ignore the redundant methods to make test logic more clear.
* Create a method to return the mocking object for reuse purpose.
h3. Motivation
* Decoupling test class {{DummyInternalVersion}} from production interface {{InternalVersion}}.
* Making test condition more clear by removing all redundant overridden methods.
* Making test logic more clear by using method stub instead of method overriding.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)