コード例 #1
0
  @Test
  public void testDivide() {
    a = 8;
    b = 2;
    int result = calculator.divide(a, b);
    Assert.assertEquals(a / b, result);

    a = 8;
    b = -2;
    result = calculator.divide(a, b);
    Assert.assertEquals(a / b, result);
  }
コード例 #2
0
 @Test
 public void testDivideByZero() {
   a = 20;
   b = 0;
   Integer result = calculator.divide(a, b);
   Assert.assertNull(result);
 }
コード例 #3
0
 @Test(expected = Exception.class)
 public void divisionWithException() {
   // divide by zero
   calculator.divide(42, 0);
 }