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

Replace try-fail-catch test patterns

    XMLWordPrintableJSON

Details

    • Test
    • Status: Resolved
    • Trivial
    • Resolution: Done
    • 8.0
    • None
    • Tests
    • 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
          284 kB
          Munendra S N
        2. SOLR-12555.patch
          340 kB
          Munendra S N
        3. SOLR-12555.patch
          332 kB
          Munendra S N
        4. SOLR-12555.patch
          28 kB
          Bar Rotstein
        5. SOLR-12555.patch
          28 kB
          Jason Gerlowski
        6. SOLR-12555-sorted-by-package.txt
          4 kB
          Jason Gerlowski
        7. SOLR-12555.txt
          15 kB
          Jason Gerlowski

        Activity

          People

            gerlowskija Jason Gerlowski
            gerlowskija Jason Gerlowski
            Votes:
            0 Vote for this issue
            Watchers:
            5 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 - 4h 20m
                4h 20m