Answer the question
In order to leave comments, you need to log in
How to pass an exception test in maven?
Hello, please help me to solve the problem.
There is a class with the following method
public int[] filterPositive(int[] array) throws NullPointerException {
if (array == null || array.length == 0)
throw new NullPointerException();
int count = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] > 0)
count++;
}
int[] arr = new int[count];
count = 0;
for (int i = 0; i < array.length; i++) {
if (array[i] > 0) {
arr[count] = array[i];
count++;
}
}
return arr;
}
@Test(expected = NullPointerException.class)
private void testFilterPositive1() throws NullPointerException{
ob.filterPositive(null);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question