Uploaded image for project: 'Apache Curator'
  1. Apache Curator
  2. CURATOR-610

Refactor CountCuratorWatcher in TestWatcherIdentity.java to improve test logic

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • None
    • 5.2.1
    • Framework
    • None

    Description

      Description

      I noticed that there is a test class CountCuratorWatcher implements production interface curatorWatcher to assist testing production class CuratorFrameworkImpl. This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.

      Current Implementation

      •  CountCuratorWatcher implements CuratorWatcher and creates a new variable to keep tracking of the method invocation status for process(WatchedEvent).
      • In test cases, after executing test target, the new variable will be used in assertion statement to check the execution status of process(WatchedEvent).

      Proposed Implementation

      • Replace CountCuratorWatcher with a mocking object created by Mockito.
      • Extract the AtomicLong attribute and use the extracted attribute to check method invocation status.
      • Use method stub to control the behavior of the mocking object.

      Motivation

      • Decouple test class `CountCuratorWatcher` from production interface `CuratorWatcher`.
      • Make test logic more clear by using method stub instead of method overriding.

      Attachments

        Activity

          People

            eolivelli Enrico Olivelli
            wx930910 Xiao Wang
            Votes:
            0 Vote for this issue
            Watchers:
            1 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 - 1h 20m
                1h 20m