Here you can find the source of assertPasswordMeetsRequirements(String password, boolean expected)
private static void assertPasswordMeetsRequirements(String password, boolean expected)
//package com.java2s; //License from project: Open Source License public class Main { private static void assertPasswordMeetsRequirements(String password, boolean expected) { boolean actual = passwordMeetsRequirements(password); String quotedPassword = (password == null) ? "null" : "\"" + password + "\""; String output = "passwordMeetsRequirements(" + quotedPassword + ") = " + actual; if (actual == expected) { output += " (expected)"; } else {/*from ww w. j a v a 2s. c om*/ output += ", expected " + expected + ". NOOOOOOOOOOOOOOOOOOOOOOOOOO!"; } System.out.println(output); } /** * Checks to see if the supplied password meets the following requirements: * Must be between 8 and 25 characters long * Contains no whitespace * Contains no slashes "/" "\" * Contains at least three of the following: * * lower case letter * * upper case letter * * digit * * other character * * @param password * @return true if the password meets the requirements, false otherwise */ public static boolean passwordMeetsRequirements(String password) { if (password == null) { return false; } if (password.length() < 8 || password.length() > 25) { return false; } boolean containsLowerCase = false; boolean containsUpperCase = false; boolean containsDigit = false; boolean containsWhitespace = false; boolean containsSlash = false; boolean containsOther = false; for (int i = 0; i < password.length(); i++) { char single = password.charAt(i); if (Character.isLowerCase(single)) { containsLowerCase = true; } else if (Character.isUpperCase(single)) { containsUpperCase = true; } else if (Character.isDigit(single)) { containsDigit = true; } else if (Character.isWhitespace(single)) { containsWhitespace = true; } else if (single == '/' || single == '\\') { containsSlash = true; } else { containsOther = true; } } if (containsWhitespace || containsSlash) { return false; } int varietyCount = 0; varietyCount += containsLowerCase ? 1 : 0; varietyCount += containsUpperCase ? 1 : 0; varietyCount += containsDigit ? 1 : 0; varietyCount += containsOther ? 1 : 0; return (varietyCount >= 3); } }