title: Correct way to JUnit test divide() method
body: <p>I've got this simple method:</p>
  
  <pre><code>public int divide(int a, int b) throws ArithmeticException {
          if (b == 0) {
              throw new ArithmeticException("Division by 0");
          } else {
              return a / b;
          }
      }
  </code></pre>
  
  <p>and I'd like to JUnit test it.</p>
  
  <p>I've done as follows:</p>
  
  <pre><code>@Test(expected = ArithmeticException.class) // Expected this exc
      public void testDivideWhenDivisorIsZero() {
          int result = c.divide(1, 0);
      }
  </code></pre>
  
  <p>which "returns" a green bar line ("tests finished successfully").</p>
  
  <ul>
  <li>Is this a correct way to JUnit test this method or should I have put a <code>try-catch</code> clause in that test?</li>
  </ul>
  
  <p><strong>EDIT</strong></p>
  
  <p>Would this JUnit test be equivalent with the following?</p>
  
  <pre><code>@Test
      public void testDivideWhenDivisorIsZero() {
          try{
              c.divide(1, 0);
              fail("Expected ArithmeticException");
          } catch(ArithmeticException e) {
  
          }
      }
  </code></pre>