You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by "Julian Reschke (Jira)" <ji...@apache.org> on 2021/11/24 10:11:00 UTC
[jira] [Closed] (JCR-4710) Refactor DummyInternalVersion in VersionIteratorImplTest.java to improve test logic
[ https://issues.apache.org/jira/browse/JCR-4710?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Julian Reschke closed JCR-4710.
-------------------------------
> 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
> Priority: Minor
> Labels: Refactoring, Test
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> 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.20.1#820001)