I have this bizarre situation with TestNG and hoping someone could help.
I'm trying to test for an IllegalArgumentException, essentially trying to block anything malicious that might end being passed into a setter on a model. The test that I have annotated with the expected exception compiles and runs fine, but it passes despite me not throwing any IllegalArgumentException in the code and I am at a loss as to why.
public class CarTest extends ModelTest {
@Test(expectedExceptions = InvalidArgumentException.class)
public void willThrowInvalidArgumentExceptionWhenSettingEngineToNull() throws InvalidArgumentException{
Car car = new Car();
car.setEngine(null);
}
}
This passes despite no thrown exception.
The model I am using is a groovy model so will have already a public setter for this property.
I have changed the model names but it shouldn't make any difference in this case.
Thank you in advance for your wisdom