Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8065651

Enhance Asserts to throw different exceptions for different types of assertions.

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 9
    • Fix Version/s: tbd
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      com.oracle.java.testlibrary.Asserts provides rich set of different assertions which are pretty handy and widely used in tests.

      Unfortunately there is no easy way to distinct actual product issue from some test issue if c.o.j.t.Asserts is used for asserting on both kind of conditions. For instance:

      public void testMathSqrtForPositiveFloats(float v) {
          Assert.assertGTE(v, 0.0f, "Hey, this test is for non-negative floats only!!!1");
          Assert.assertEQ(Math.sqrt(v), ourVeryOwnSqrt(v), "Square root should be equal");
      }

      It would be nice to have an ability to throw distinct exceptions, but use similar API for both types of assertions.

      Applying it to example above, second assertion should throw RuntimeException as it throwing now, but the first assertion should throw Error or AssertionFailure.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              fzhinkin Filipp Zhinkin
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: