@Test( expected = AnyException.class )
@Test( expected = ArithmeticException.class )
public void test_Expected_Exception_is_ArithmeticException(){
int number = 1 / 0;
}
Here this test must throw ArithmeticException, If it does not then test will fail.
@Test( expected = IndexOutOfBoundsException.class )
public void test_Expected_Exception_is_IndexOutOfBoundException(){
(new ArrayList()).get(1);
}
Here this test must throw IndexOutOfBoundsException, If it does not then test will fail.
@Test( expected = ArrayIndexOutOfBoundsException.class )
public void test_Expected_Exception_is_ArrayIndexOutOfBoundException(){
int[] array = new int[1];
int number = array[3];
}
Here this test must throw ArrayIndexOutOfBoundsException, If it does not then test will fail.