Uploaded image for project: 'Geode'
  1. Geode
  2. GEODE-9897

ClientUserAuthsTest leaves some seemingly tested responsibilities untested

    XMLWordPrintableJSON

Details

    Description

      Problem 1: The test class's before() method uses the spy() mechanism to override getNextId() on the ClientUserAuths it is testing. This bypasses the actual implementation for all tests, leaving untested the following important ClientUserAuths responsibilities:

      • Detect when all IDs have all been used.
      • Clear all existing authentications when all IDs have been used, to force reauthentication.
      • Re-seed the ID generator when all IDs have been used.

      The tests are likely doing this because getNextId() relies on a Random, which is uncontrollable by design. Because ClientUserAuths creates the Random, the tests are unable to inject a testable instance, and so instead must bypass the ClientUserAuths methods that interact with the Random.

      The solution to this problem is to extract and test an ID generator that accepts a Random as a constructor parameter, thus allowing tests to control it.

      This also frees ClientUserAuths from the responsibility to generate IDs, so it can instead focus on how it uses the IDs. Then it will be straightforward to write tests to verify that ClientUserAuths forces reauthentication when the generator runs out of IDs.

      Problem 2: Several tests in this class attempt to verify certain responsibilities only by spying on how the ClientUserAuths interacts with itself. Verifying only these internal interactions leaves the actual responsibilities (how the ClientUserAuths responds to subsequent calls) untested.

      The tests can instead verify the actual responsibilities by calling public methods and making assertions about the returned values.

      Attachments

        Activity

          People

            demery Dale Emery
            demery Dale Emery
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: