In: Computer Science
Task Intro: Password JAVA and JUnit5(UNIT TESTING)
Write a method that checks a password. The rules for the password are:
- The password must be at least 10 characters. - The password can only be numbers and letters. - Password must have at least 3 numbers.
Write a test class(Junit5/Unit testing) that tests the checkPassword method.
Hint: You can (really should) use method from built-in String class:
public boolean matches(String regex)
to check that the current string matches a regular expression. For example, if the variable "password" is the string to be checked, so will the expression.
password.matches("(?:\\D*\\d){3,}.*")
return true if the string contains at least 3 numbers. Regular expression "^ [a-zA-Z0-9] * $" can be used to check that the password contains only numbers and letters.
Let your solution consist of 4 methods:
checkPassword(string password) [only test this method] checkPasswordLength(string password) [checkPassword help method] checkPasswordForAlphanumerics(string password) [checkPassword help method] checkPasswordForDigitCount(string password) [checkPassword help method]
Intro: Password Criteria
The code is structured and formatted Your code uses the standard java formatting and naming standard, it is also nicely formatted with the right indentation etc.
Good and descriptive variable names Your code uses good variable names that describe the damped function, such as "counter" instead of "abc".
The code is logical and understandable
Your code is structured in a logical way so it's easy to understand what you've done and how to solve the problem. It should be easy for others to understand what your code does and how it works.
The solution shows understanding of the problem You show with your code that you have thought about and understood the problem. It is worth thinking about how you will solve the problem before you actually solve it
The code solves the problem Your code manages to do what is required in the assignment text, and it does not do unnecessary things either.
Unit tests (Junit5) cover all common use cases Unit tests for your code check all common ways it can be used, such as the isEven (int number) method being tested with even, odd, negative, and null, reverseString (String text) will be checked with regular string, empty string and zero object, etc.
The code uses Regex and built-in methods Do not try to reinvent the wheel, it is possible to check the text string for digits with a while / for loop, but using regex and matching function is much easier. There are many websites that help you find regex for what you need, so use them.