Need help to understand what i am doing wrong. Here is my test case with list of users, where the required fields for user set to null, If the required field is missing, throwing an argument exception with message.Also checked my method it seems good.
//Test case begins
@Test(groups = {"unit"})
public void testProcessOrderWithMissingFieldsForUsers() throws Exception {
GenericOrder order = getOrder();
List<User> users = order.getUsers();
User user = users.get(0);
user.setLastName(null);
user.setLoginName(null);
user.setEmailAddress(null);
user.setRole(null);
try {
orderService.processOrder(order);
} catch (ArgumentException aex) {
Assert.assertEquals(aex.getFieldErrors().get(0).getMessage(),"lastName is required");
Assert.assertEquals(aex.getFieldErrors().get(1).getMessage(), "loginName is required");
Assert.assertEquals(aex.getFieldErrors().get(2).getMessage(), "emailAddress is required");
Assert.assertEquals(aex.getFieldErrors().get(3).getMessage(), "role is required");
}
It is likely the errors are not in the order you expect them.
Further it would be better to split the test so that each validation is verified individually. In other words have ...WithMissingLastName, ...WithMissingLogin, ...WithMissingEmailAdress, ...WithMissingRole tests.
This makes for easier diagnostics and it is probably closer to what you really intend to test.
Also your test will not fail if the validation is never applied. One way to protect against that is to call the fail method inside the try/catch block.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments