[
https://issues.apache.org/jira/browse/LANG-1671?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17489545#comment-17489545
]
Justyna Kubica-Ledzion commented on LANG-1671:
----------------------------------------------
Hi, I’ve prepared PR for this issue:
https://github.com/apache/commons-lang/pull/851
Proposed changes:
* replacing _AtomicSafeInitializerTestImpl_ with a spy using Mockito,
* stubbing a method _initialize(),_
* adding verification that method _initialize()_ is called only once.
Similar modification I’ve done in class {_}LazyInitializerTest{_}.
Could you please review and let me know if this modifications are Ok?
I would appreciate any feedback.
Justyna
> 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
> Priority: Minor
>
> 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.20.1#820001)