From 5de9fadc4068cb70b4adaeb9897f3df4fd5422b7 Mon Sep 17 00:00:00 2001 From: binsky Date: Sat, 5 Feb 2022 14:34:58 +0100 Subject: [PATCH] refactor minimum password length tests and add getter/setter --- src/main/java/PasswordValidator.java | 8 ++++++++ src/test/java/PasswordValidatorTest.java | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/PasswordValidator.java b/src/main/java/PasswordValidator.java index e469c92..123fa9b 100644 --- a/src/main/java/PasswordValidator.java +++ b/src/main/java/PasswordValidator.java @@ -4,4 +4,12 @@ public class PasswordValidator { public boolean validate(String password) { return password.length() >= minLength; } + + public int getMinLength() { + return minLength; + } + + public void setMinLength(int minLength) { + this.minLength = minLength; + } } diff --git a/src/test/java/PasswordValidatorTest.java b/src/test/java/PasswordValidatorTest.java index e40fa23..0079f22 100644 --- a/src/test/java/PasswordValidatorTest.java +++ b/src/test/java/PasswordValidatorTest.java @@ -10,6 +10,9 @@ class PasswordValidatorTest { assertFalse(passwordValidator.validate("")); // test minimum password length + passwordValidator.setMinLength(6); + assertFalse(passwordValidator.validate("abcde")); assertTrue(passwordValidator.validate("abcdef")); + assertTrue(passwordValidator.validate("abcdefg")); } }