[ 
https://issues.apache.org/jira/browse/LANG-1671?focusedWorklogId=725679&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-725679
 ]

ASF GitHub Bot logged work on LANG-1671:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Feb/22 13:10
            Start Date: 12/Feb/22 13:10
    Worklog Time Spent: 10m 
      Work Description: garydgregory commented on pull request #851:
URL: https://github.com/apache/commons-lang/pull/851#issuecomment-1037221768


   A PR without a description, even if it is only a URL to a ticket, is harder 
to follow than it has to be.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

            Worklog Id:     (was: 725679)
    Remaining Estimate: 0h
            Time Spent: 10m

> 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
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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)

Reply via email to