I wrote a following test case. ImprovedAlternateIterator is a custom iterator that can accept multiple iterator in its constructor. I wrote a test case to check its hasNext function. I am sure that it will throw an error but I don't know how to handle it. In junit4 we can use @Test(expected = exception.class)
and its not possible in junit5.
I followed the documents and wrote the following test case with junit5 but it failed.
@Test
public void hasNextTestWithEmptyConstructor()
ImprovedAlternateIterator <E> alternatingIterator = new ImprovedAlternateIterator<E>();
assertThrows(ArrayIndexOutOfBoundsException.class, () ->
alternatingIterator.hasNext());
}
How can I handle the exception?