0

I have validator validating, for instance, input data. It gets object product (class Product) created with default constructor. One of Product fields is description, and it has @NotNull annotation.

When I run test it fails obviously and shows NullPointerException. I can surround part of code where NullPointerException was thrown with if-else like this

if(description!=null){
 // product validation
}else{
  errors.rejectValue("description", errorCode, defaultMessage);
} 

That works, but i need something else, maybe using annotations.

dawidklos
  • 902
  • 1
  • 9
  • 32

1 Answers1

1

You con use something like Mockito to create a mock of the BindingResult that has a method hasErrors() to check for any errors.

See more solutions...

Community
  • 1
  • 1
Braj
  • 46,415
  • 5
  • 60
  • 76