Skip to content

Instantly share code, notes, and snippets.

@catalinsgh
Created June 30, 2020 18:40
Show Gist options
  • Save catalinsgh/59cb409ecf10d76611e844390195b09a to your computer and use it in GitHub Desktop.
Save catalinsgh/59cb409ecf10d76611e844390195b09a to your computer and use it in GitHub Desktop.
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,
"test123!" to false,
"t " to false,
" " to false
).map { (password, expected) ->
dynamicTest(
"given \"$password\", " +
"when validating the password, " +
"then it should be reported as ${if (expected) "valid" else "invalid"}"
) {
val actual = validator.isValid(password)
assertThat(actual).isEqualTo(expected)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment