P
P
parkito2016-04-02 20:07:47
Java
parkito, 2016-04-02 20:07:47

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;
    }

Need to pass a test that works with an exception
@Test(expected = NullPointerException.class)
    private void testFilterPositive1() throws NullPointerException{
        ob.filterPositive(null);
    }

However, it doesn't work and I don't understand why.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
parkito, 2016-04-02
@parkito

Method

@Test(expected = NullPointerException.class)
    private void testFilterPositive1() throws NullPointerException{
        ob.filterPositive(null);
    }

private - that did not work. Need to change it topublic

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question