Java's for each loop

hi @harwind -
According to the code you have pasted when you pass 1 into the method hasApplicationNumber an IllegalArgumentException will be thrown. So the test should fail.
I’ve also noticed that you are using double in the ApplicationData class but treating them as int in the hasApplicationNumber method.
Here is a stripped down version without the ApplicationData class and using int.

public class DevTalkTest {

    private final int[] numbers = new int[]{9, 7, 400};

    @Test
    public void shouldHaveApplicationNumber1() {
        assertTrue(hasApplicationNumber(1));
    }


    public boolean hasApplicationNumber(int number) {
        if (number <= 3) {
            throw new IllegalArgumentException("bad number");
        }
        for (int num : numbers) {
            if (num == number) return true;
        }
        return false;
    }


}

The tests will fail with the error:

bad number
java.lang.IllegalArgumentException: bad number
. . . 
2 Likes