passing static method as parameter in Java
I am afraid your tests are of low quality.
The problems that should be fixed immediately include
UserCredentialsValidator.usernameValidation(username, userList);
The method shouldn't take the second argument. The place from where that list is retrieved should be concealed from the API consumer.List<String> correctEmails = Arrays.asList(...)
andList<String> correctUsernames = Arrays.asList(...)
should be removed. You'd better make the tests parameterised with@ParameterizedTest
and@ValueSource
.I'd rather remove the
System.out.println
statements. They make little sense in tests.
@ParameterizedTest
@ValueSource(strings = {"[email protected]", "[email protected]"})
void testUserEmailValidationWithValidUserEmailShouldPass(String validUserEmail) {
boolean isValid = UserCredentialsValidator.emailValidator(validUserEmail);
assertTrue(isValid);
}
@ParameterizedTest
@ValueSource(strings = {"username", "123username"})
void testUserNameValidationWithValidUserNameShouldPass(String validUserName) {
boolean isValid = UserCredentialsValidator.usernameValidation(validUserName);
assertTrue(isValid);
}
Now there is nothing to reduce.