@@ -62,11 +62,12 @@ public boolean supports(Class c) {
62
62
* @should pass validation if all required fields have proper values
63
63
* @should fail validation if email as username enabled and email invalid
64
64
* @should fail validation if email as username disabled and email provided
65
+ * @should not throw NPE when user is null
65
66
*/
66
67
public void validate (Object obj , Errors errors ) {
67
68
User user = (User ) obj ;
68
69
if (user == null ) {
69
- errors .rejectValue ( "user" , "error.general" );
70
+ errors .reject ( "error.general" );
70
71
} else {
71
72
if (user .isRetired () && StringUtils .isBlank (user .getRetireReason ()))
72
73
errors .rejectValue ("retireReason" , "error.null" );
@@ -84,19 +85,20 @@ public void validate(Object obj, Errors errors) {
84
85
if (person .getPersonName () == null || StringUtils .isEmpty (person .getPersonName ().toString ()))
85
86
errors .rejectValue ("person" , "Person.names.length" );
86
87
}
87
- }
88
- AdministrationService as = Context .getAdministrationService ();
89
- boolean emailAsUsername = Boolean .parseBoolean (as .getGlobalProperty (
90
- OpenmrsConstants .GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME , "false" ));
91
- if (emailAsUsername ) {
92
- boolean isValidUserName = isUserNameAsEmailValid (user .getUsername ());
93
- if (!isValidUserName ) {
94
- errors .rejectValue ("username" , "error.username.email" );
95
- }
96
- } else {
97
- boolean isValidUserName = isUserNameValid (user .getUsername ());
98
- if (!isValidUserName ) {
99
- errors .rejectValue ("username" , "error.username.pattern" );
88
+
89
+ AdministrationService as = Context .getAdministrationService ();
90
+ boolean emailAsUsername = Boolean .parseBoolean (as .getGlobalProperty (
91
+ OpenmrsConstants .GLOBAL_PROPERTY_USER_REQUIRE_EMAIL_AS_USERNAME , "false" ));
92
+ if (emailAsUsername ) {
93
+ boolean isValidUserName = isUserNameAsEmailValid (user .getUsername ());
94
+ if (!isValidUserName ) {
95
+ errors .rejectValue ("username" , "error.username.email" );
96
+ }
97
+ } else {
98
+ boolean isValidUserName = isUserNameValid (user .getUsername ());
99
+ if (!isValidUserName ) {
100
+ errors .rejectValue ("username" , "error.username.pattern" );
101
+ }
100
102
}
101
103
}
102
104
}
0 commit comments