-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordSpacesAndRepeatingCharactersRequirement.java
48 lines (35 loc) · 1.35 KB
/
PasswordSpacesAndRepeatingCharactersRequirement.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package com.jcp.automation.common.requirements;
import com.jcp.automation.common.ErrorCodes;
import java.util.regex.Pattern;
/**
* @author ykrasnopolskiy
* @since 3/19/17.
*/
public class PasswordSpacesAndRepeatingCharactersRequirement extends AbstractRequirement {
private Pattern spaces = Pattern.compile("[\\s\\t]");
private String repeatingCharactersRegex = ".*(.)\\1{2}.*";
public Pattern getSpaces() {
return spaces;
}
public void setSpaces(Pattern spaces) {
this.spaces = spaces;
}
public String getRepeatingCharactersRegex() {
return repeatingCharactersRegex;
}
public void setRepeatingCharactersRegex(String repeatingCharactersRegex) {
this.repeatingCharactersRegex = repeatingCharactersRegex;
}
/**
* The constructor is planned to be used only to instantiate Requirement inside Requirements enum
*/
PasswordSpacesAndRepeatingCharactersRequirement(ErrorCodes associatedErrorIfNotMeetRequiement){
setErrorCode(associatedErrorIfNotMeetRequiement);
}
@Override
public boolean meets(Object objectToCheck) {
return objectToCheck == null
|| !spaces.matcher(objectToCheck.toString()).find()
|| !objectToCheck.toString().matches(repeatingCharactersRegex);
}
}