File tree Expand file tree Collapse file tree
java-strings/src/test/java/com/baeldung/string Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ public class StringContainingCharactersUnitTest {
1111
1212 private static final Pattern [] inputRegexes = new Pattern [4 ];
1313
14+ private static final String regex = "^(?=.*?\\ p{Lu})(?=.*?\\ p{Ll})(?=.*?\\ d)(?=.*?[`~!@#$%^&*()\\ -_=+\\ \\ |\\ [{\\ ]};:'\" ,<.>/?]).*$" ;
15+
1416 static {
1517 inputRegexes [0 ] = Pattern .compile (".*[A-Z].*" );
1618 inputRegexes [1 ] = Pattern .compile (".*[a-z].*" );
@@ -95,4 +97,40 @@ public void givenInvalidStrings_whenChecking_thenNotCorrect() {
9597 invalidInput = "b3;" ;
9698 assertFalse (checkString (invalidInput ));
9799 }
100+
101+ @ Test
102+ public void givenSingleRegex_whenMatchingCorrectString_thenMatches () {
103+ String validInput = "Ab3;" ;
104+ assertTrue (Pattern
105+ .compile (regex )
106+ .matcher (validInput )
107+ .matches ());
108+ }
109+
110+ @ Test
111+ public void givenSingleRegex_whenMatchingWrongStrings_thenNotMatching () {
112+ String invalidInput = "Ab3" ;
113+ assertFalse (Pattern
114+ .compile (regex )
115+ .matcher (invalidInput )
116+ .matches ());
117+
118+ invalidInput = "Ab;" ;
119+ assertFalse (Pattern
120+ .compile (regex )
121+ .matcher (invalidInput )
122+ .matches ());
123+
124+ invalidInput = "A3;" ;
125+ assertFalse (Pattern
126+ .compile (regex )
127+ .matcher (invalidInput )
128+ .matches ());
129+
130+ invalidInput = "b3;" ;
131+ assertFalse (Pattern
132+ .compile (regex )
133+ .matcher (invalidInput )
134+ .matches ());
135+ }
98136}
You can’t perform that action at this time.
0 commit comments