Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-2717

Refactor MockChannelListener in DataContextDataChannelEventsIT to improve test logic

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • None
    • None

    Description

      Description

      I noticed that there is a test class MockChannelListener implements production interface DataChannelListener to assist testing the ineractions among commitChanges(), commitChangesToParent() and rollbackChanges(). This might not be the best practice in testing and can be improved by leveraging mocking frameworks.

      Current Implementation

      • MockChannelListener implements DataChannelListener. The sub test class creates three fields to keep tracking the invocation status of three overridden methods.
      • In test cases, an instance of MockChannelListener is passed to EventUtil.listenForChannelEvents(DataChannel, DataChannelListener). The new fields in test sub class are used in assertion statements to assert test sub class's behavior.

      Proposed Implementation

      • Replace MockChannelListener with a mocking object created by Mockito.
      • Remove the fields created in test subclass to make test logic more clear.
      • Remove the redundant method overrides to make test logic more clear.
      • Use Mockito.verify() to directly verify the behavior of the mocking object and make test condition more explict.

      Motivation

      • Decoupling test class MockChannelListener from production interface DataChannelListener
      • Making test condition more clear by removing redundant overridden methods and new fields.
      • Use Mockito.verify() to directly verify the behavior of the mocking object and make test condition more explict.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 2h
                2h
                Remaining:
                Remaining Estimate - 2h
                2h
                Logged:
                Time Spent - Not Specified
                Not Specified