Skip to content

Commit d565759

Browse files
committed
1 parent cfe3408 commit d565759

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

kata/5-kyu/regex-password-validation/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ You need to write regex that will validate a password to make sure it meets the
66
* contains a lowercase letter
77
* contains an uppercase letter
88
* contains a digit
9-
* only contains alphanumeric characters (note that `'_'` is not alphanumeric)
9+
* only contains alphanumeric characters (note that `'_'` is not alphanumeric)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
interface PasswordRegex {
2+
String REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,}$";
3+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import static org.junit.jupiter.api.Assertions.assertFalse;
2+
import static org.junit.jupiter.api.Assertions.assertTrue;
3+
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.ValueSource;
6+
7+
class SolutionTest {
8+
@ParameterizedTest
9+
@ValueSource(strings = {
10+
"fjd3IR9",
11+
"4fdg5Fj3",
12+
"djI38D55",
13+
"123abcABC",
14+
"ABC123abc",
15+
"Password123"
16+
})
17+
void valid(String password) {
18+
assertTrue(password.matches(PasswordRegex.REGEX));
19+
}
20+
21+
@ParameterizedTest
22+
@ValueSource(strings = {
23+
"ghdfj32",
24+
"DSJKHD23",
25+
"dsF43",
26+
"DHSJdhjsU",
27+
"fjd3IR9.;",
28+
"fjd3 IR9",
29+
"djI3_8D55",
30+
"@@",
31+
"JHD5FJ53",
32+
"!fdjn345",
33+
"jfkdfj3j",
34+
"123",
35+
"abc",
36+
""
37+
})
38+
void invalid(String password) {
39+
assertFalse(password.matches(PasswordRegex.REGEX));
40+
}
41+
}

0 commit comments

Comments
 (0)