This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class PasswordValidatorTest { | |
private val validator = PasswordValidator() | |
@TestFactory | |
fun `given input password, when validating it, then is should return if it is valid`() = | |
listOf( | |
"Test123!" to true, | |
"#tesT12!" to true, | |
"12Es@t123" to true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class PasswordValidatorTest { | |
private val validator = PasswordValidator() | |
@ParameterizedTest(name = "given \"{0}\", when validating the password, then it should return {1}") | |
@MethodSource("passwordArguments") | |
fun `given input password, when validating it, then is should return if it is valid`( | |
password: String, | |
expected: Boolean | |
) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordValidator { | |
fun isValid(password: String) = PATTERN.matcher(password).matches() | |
private companion object { | |
val PATTERN: Pattern = Pattern.compile("^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@\$%^&*-]).{8,}\$") | |
} | |
} |