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{L}&&[^\\ p{Lu}]])(?=.*?\\ d)" + "(?=.*?[`~!@#$%^&*()\\ -_=+\\ \\ \\ |\\ [{\\ ]};:'\" ,<.>/?]).*$" ;
15+
1416 static {
1517 inputRegexes [0 ] = Pattern .compile (".*[A-Z].*" );
1618 inputRegexes [1 ] = Pattern .compile (".*[a-z].*" );
@@ -95,4 +97,25 @@ 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 .compile (regex ).matcher (validInput ).matches ());
105+ }
106+
107+ @ Test
108+ public void givenSingleRegex_whenMatchingWrongStrings_thenNotMatching () {
109+ String invalidInput = "Ab3" ;
110+ assertFalse (Pattern .compile (regex ).matcher (invalidInput ).matches ());
111+
112+ invalidInput = "Ab;" ;
113+ assertFalse (Pattern .compile (regex ).matcher (invalidInput ).matches ());
114+
115+ invalidInput = "A3;" ;
116+ assertFalse (Pattern .compile (regex ).matcher (invalidInput ).matches ());
117+
118+ invalidInput = "b3;" ;
119+ assertFalse (Pattern .compile (regex ).matcher (invalidInput ).matches ());
120+ }
98121}
You can’t perform that action at this time.
0 commit comments