Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-12555

Replace try-fail-catch test patterns

    Details

    • Type: Test
    • Status: Open
    • Priority: Trivial
    • Resolution: Unresolved
    • Affects Version/s: 8.0
    • Fix Version/s: None
    • Component/s: Tests
    • Security Level: Public (Default Security Level. Issues are Public)
    • Labels:
      None

      Description

      I recently added some test code through SOLR-12427 which used the following test anti-pattern:

      try {
          actionExpectedToThrowException();
          fail("I expected this to throw an exception, but it didn't");
      catch (Exception e) {
          assertOnThrownException(e);
      }
      

      Hoss (rightfully) objected that this should instead be written using the formulation below, which is clearer and more concise.

      SolrException e = expectThrows(() -> {...});
      

      We should remove many of these older formulations where it makes sense. Many of them were written before expectThrows was introduced, and having the old style assertions around makes it easier for them to continue creeping in.

        Attachments

        1. SOLR-12555.patch
          28 kB
          Bar Rotstein
        2. SOLR-12555.patch
          28 kB
          Jason Gerlowski
        3. SOLR-12555.txt
          15 kB
          Jason Gerlowski
        4. SOLR-12555-sorted-by-package.txt
          4 kB
          Jason Gerlowski

          Activity

            People

            • Assignee:
              gerlowskija Jason Gerlowski
              Reporter:
              gerlowskija Jason Gerlowski
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:

                Time Tracking

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