Hey,
The main problem I'm having is dealing with the Errors object in the context of JUnit.
In setUp() I instantiate three domain objects. One I set with good values. One I set with blank values. And another I fill with bad values. I then pass each of them through my validation object, passing also three BindExceptions I instantiated (errorsGood, errorsBad, & errorsBlank).
Code:
private ComputerValidator computerValidator;
private Computer computerGood, computerBlank, computerBad;
private BindException errorsGood, errorsBad, errorsBlank;
public void setUp(){
ComputerValidator computerValidator = new ComputerValidator();
Computer computerGood = new Computer();
Computer computerBad = new Computer();
Computer computerBlank = new Computer();
BindException errorsGood = new BindException(computerGood, "computerGood");
BindException errorsBad = new BindException(computerBad, "computerBad");
BindException errorsBlank = new BindException(computerBlank, "computerBlank");
computerGood.setRow(29);
computerGood.setIp("156.152.1.123");
computerGood.setSeat(3);
computerGood.setHostname("LOGOS");
computerGood.setOs("Windows XP");
computerBad.setRow(42);
computerBad.setIp("www.cpog.com");
computerBad.setSeat(11);
computerValidator.validate(computerGood, errorsGood);
computerValidator.validate(computerBad, errorsBad);
computerValidator.validate(computerBlank, errorsBlank);
}
Then in my test code I have the following:
Code:
public void testValidateInfo(){
boolean hasErrorsGood = errorsGood.hasErrors();
boolean hasErrorsBad = errorsBad.hasErrors();
boolean hasErrorsBlank = errorsBlank.hasErrors();
assertEquals(true, hasErrorsBlank);
assertEquals(false, hasErrorsGood);
assertEquals(false, hasErrorsBad);
}
This obviously doesn't work because I get a NullPointerException on "errorsGood.hasErrors();"
Any help would be great.
Thanks,
James Winans