I created the following method that I use to validate Roman numbers converter. In JUnit the test passes but the program doesn't throw any exception. Where did I wrong?
public void validateState(String number){
if(!number.matches("^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$"))
throw new IllegalArgumentException("Invalid number");
System.out.println("Invalid number");
}
Test:
@Test(expected = IllegalArgumentException.class)
public void test15() throws Exception {
new RomanNumber("").validateState("MMMMM");
}
Thank you for the help.