Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-38694

Simplify Java UT code with Junit `assertThrows`

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 3.4.0
    • 3.4.0
    • Tests
    • None

    Description

      There are some code patterns in Java UTs:

       @Test
        public void testAuthReplay() throws Exception {
          try {
            doSomeOperation();
            fail("Should have failed");
          } catch (Exception e) {
            assertTrue(checkException(e));
          }
        }
      

      or 

       

      @Test(expected = SomeException.class)
        public void testAuthReplay() throws Exception {
          try {
            doSomeOperation();
            fail("Should have failed");
          } catch (Exception e) {
            assertTrue(checkException(e));
            throw e;
          }
        } 

      we can use Junit assertThrows to simplify the similar patterns

       

       

      Attachments

        Activity

          People

            LuciferYang Yang Jie
            LuciferYang Yang Jie
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: