Uploaded image for project: 'Qpid Proton'
  1. Qpid Proton
  2. PROTON-2431

Refactor SinkHandler in ReactorTest.java to improve test design

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • proton-j

    Description

      Description

      I noticed that there is a test class SinkHandler implements production class BaseHandler to assist testing methd ReactorImpl:run(). This might not be the best priactice in unit testing and can be improved by leveraging mocking frameworks.

      Current Implementation

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

      Proposed Implementation

      • Replace SinkHandler with a mocking object created by Mockito.
      • Extract the attribute into transfer(int, int) to surface counting logic.
      • Use method stub to control the behavior of the mocking object.

      Motivation

      • Decouple test class SinkHandler from production class `BaseHandler`.
      • 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:
            1 Start watching this issue

            Dates

              Created:
              Updated: