Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1671

Refactor AtomicSafeInitializerTest to improve test design

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Not A Problem
    • None
    • None
    • lang.concurrent.*
    • None

    Description

      Description

      I noticed that there is a test class AtomicSafeInitializerTestImpl extends production class AtomicSafeInitializer to assist testing method AtomicSafeInitializer.get(). This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.

      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().

      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.

      Motivation

      • Decouple test class AtomicSafeInitializerTestImpl from production interface AtomicSafeInitializer.
      • Make test logic more clear by using method stub instead of method overriding.

      Attachments

        Activity

          People

            Unassigned Unassigned
            wx930910 Xiao Wang
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 50m
                50m