@Test @Override public void testDefinedMoreThanOnePropertyValues() { setDefinedMoreThanOneSettings(); AtLeastXDigitPasswordRule rule = newRuleInstanceForTest(); assertThat(rule.getValue(), is(2)); assertThat(rule.isRequired(), is(true)); assertThat(rule.isCombined(), is(false)); for (int i = 0; i < NB_LOOP; i++) { assertThat(Pattern.compile("[0-9]{2,}").matcher(rule.random()).find(), is(true)); } assertThat(rule.check("1RbRZ"), is(false)); assertThat(rule.check("1R9Rz"), is(true)); assertThat(rule.check("1R0Rz"), is(true)); }
@Test public void testCommons() { AtLeastXDigitPasswordRule rule = newRuleInstanceForTest(); assertThat(rule.getType(), is(PasswordRuleType.AT_LEAST_X_DIGIT)); assertThat(rule.check("ajlkaslkj"), is(false)); for (char c = 97; c < (97 + 26); c++) { assertThat(rule.check("a" + c + "zdzdz"), is(false)); } for (char c = 65; c < (65 + 26); c++) { assertThat(rule.check("a" + c + "dzzd"), is(false)); } for (int i = 0; i < 10; i++) { assertThat(rule.check("ajlkaslkj" + i), is(true)); } for (int i = 0; i < NB_LOOP; i++) { assertThat(Pattern.compile("[a-z]+").matcher(rule.random()).find(), is(false)); assertThat(Pattern.compile("[A-Z]+").matcher(rule.random()).find(), is(false)); assertThat(Pattern.compile("[0-9]+").matcher(rule.random()).find(), is(true)); } }