I just wanted to write a test for a User class to check the validation. I'm wondering that nothing is validated as annotated.
@Entity
public class User {
@Id
@NotBlank
@Size(min = 2, max = 255)
private String username;
@NotBlank
@Column(length = 60)
private String password;
public User(String username, String password) {
this.username = username.trim();
this.password = password;
}
}
Now I'm trying this:
User user2 = new User("admin", "");
User user3 = new User("", "test");
User user4 = new User("", "");
And I assumed some exceptions but nothing.
- So is there a way to test these annotations?
- And when are those validations fired up?