Xiao Wang created LANG-1671:
-------------------------------
Summary: Refactor AtomicSafeInitializerTest to improve test design
Key: LANG-1671
URL: https://issues.apache.org/jira/browse/LANG-1671
Project: Commons Lang
Issue Type: Improvement
Components: lang.concurrent.*
Reporter: Xiao Wang
h3. Description
I noticed that there is a test class
[AtomicSafeInitializerTestImpl|https://github.com/apache/commons-lang/blob/69c9593cc1da760bb4dbcf32f4ae755c54376b77/src/test/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializerTest.java#L67]
extends production class
[AtomicSafeInitializer|https://github.com/apache/commons-lang/blob/69c9593cc1da760bb4dbcf32f4ae755c54376b77/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java#L55]
to assist testing method
[AtomicSafeInitializer.get()|https://github.com/apache/commons-lang/blob/69c9593cc1da760bb4dbcf32f4ae755c54376b77/src/main/java/org/apache/commons/lang3/concurrent/AtomicSafeInitializer.java#L72].
This might not be the best priactice in unit testing and can be improved by
leveraging mocking frameworks.
h3. Current Implementation
* {{AtomicSafeInitializerTestImpl}} extends {{AtomicSafeInitializer}} and
creates a new variable to keep tracking of the method invocation status for
{{initialize()}}.
* In test cases, after executing {{AtomicSafeInitializer.get()}}, the new
variable will be used in assertion statement to check the execution status of
{{initialize()}}.
h3. Proposed Implementation
* Replace {{AtomicSafeInitializerTestImpl}} with a mocking object created by
Mockito.
* Extract the AtomicLong attribute and use the extracted attribute in test
case to check method invocation status.
* Use method stub to control the behavior of the mocking object.
h3. Motivation
* Decouple test class {{AtomicSafeInitializerTestImpl}} from production
interface {{AtomicSafeInitializer}}.
* Make test logic more clear by using method stub instead of method overriding.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)