@Test
  public void testAdHocRestriction() {
    List<PasswordRestriction> restrictions = new ArrayList<PasswordRestriction>();
    restrictions.add(ALPHA_RESTRICTION);
    restrictions.add(SYMBOL_RESTRICTION);
    SimplePasswordStrengthChecker checker =
        new SimplePasswordStrengthChecker(restrictions, this.dictionary, this.keyboard);
    String pwd = "!#*_3x";
    List<PasswordRestriction> adHocRestrictions = new ArrayList<PasswordRestriction>();
    ValueRestriction restriction = new ValueRestriction(new String[] {pwd});
    adHocRestrictions.add(restriction);

    PasswordStrengthCheckResult result = checker.check("", pwd, adHocRestrictions);
    assertNotNull(result);
    assertNotNull(result.getPassedRestrictions());
    assertNotNull(result.getRestrictionFailures());

    assertEquals(2, result.getPassedRestrictions().size());
    assertEquals(1, result.getRestrictionFailures().size());

    assertNotNull(result.getStrength());

    assertEquals(ALPHA_RESTRICTION, result.getPassedRestrictions().get(0));
    assertEquals(SYMBOL_RESTRICTION, result.getPassedRestrictions().get(1));
    assertEquals(
        MESSAGES.passwordMustNotBeEqual(pwd).getMessage(),
        result.getRestrictionFailures().get(0).getMessage());
  }
  @Test
  public void testLengthRestriction() {
    List<PasswordRestriction> restrictions = new ArrayList<PasswordRestriction>();
    // one that will fail
    restrictions.add(LENGTH_RESTRICTION);
    // one that will pass
    restrictions.add(SYMBOL_RESTRICTION);
    SimplePasswordStrengthChecker checker =
        new SimplePasswordStrengthChecker(restrictions, this.dictionary, this.keyboard);
    String pwd = "1W2sa#4";
    PasswordStrengthCheckResult result = checker.check("", pwd, null);
    assertNotNull(result);
    assertNotNull(result.getPassedRestrictions());
    assertNotNull(result.getRestrictionFailures());

    assertEquals(1, result.getPassedRestrictions().size());
    assertEquals(1, result.getRestrictionFailures().size());

    assertNotNull(result.getStrength());

    assertEquals(
        MESSAGES.passwordNotLongEnough(8).getMessage(),
        result.getRestrictionFailures().get(0).getMessage());
    assertEquals(SYMBOL_RESTRICTION, result.getPassedRestrictions().get(0));
  }
  @Test
  public void testDigitsRestriction() {
    List<PasswordRestriction> restrictions = new ArrayList<PasswordRestriction>();
    // one that will fail
    restrictions.add(DIGIT_RESTRICTION);
    // one that will pass
    restrictions.add(ALPHA_RESTRICTION);
    SimplePasswordStrengthChecker checker =
        new SimplePasswordStrengthChecker(restrictions, this.dictionary, this.keyboard);
    String pwd = "DW$sa#x";
    PasswordStrengthCheckResult result = checker.check("", pwd, null);
    assertNotNull(result);
    assertNotNull(result.getPassedRestrictions());
    assertNotNull(result.getRestrictionFailures());

    assertEquals(1, result.getPassedRestrictions().size());
    assertEquals(1, result.getRestrictionFailures().size());

    assertNotNull(result.getStrength());

    assertEquals(
        MESSAGES.passwordMustHaveDigit(1), result.getRestrictionFailures().get(0).getMessage());
    assertEquals(ALPHA_RESTRICTION, result.getPassedRestrictions().get(0));
  }