Skip to content

Instantly share code, notes, and snippets.

View catalinsgh's full-sized avatar

Catalin Gheorghe catalinsgh

View GitHub Profile
@catalinsgh
catalinsgh / PasswordValidatorTest.kt
Created June 30, 2020 18:40
PasswordValidatorTest using dynamic tests
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,
@catalinsgh
catalinsgh / PasswordValidatorTest.kt
Created June 29, 2020 19:48
PasswordValidatorTest using ParameterizedTest
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
) {
@catalinsgh
catalinsgh / PasswordValidator.kt
Created June 29, 2020 19:22
Class used to validate that a string matches a certain set of criteria
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,}\$")
}
}