CharacterRuleProvider { public static List<CharacterRule> getCharacterRules(final StringGenerationParameters parameters) { final List<CharacterRule> characterRules = new ArrayList<>(); if (parameters.isIncludeSpecial()) { characterRules.add(new CharacterRule(CredHubCharacterData.SPECIAL)); } if (!parameters.isExcludeNumber()) { characterRules.add(new CharacterRule(EnglishCharacterData.Digit)); } if (!parameters.isExcludeUpper()) { characterRules.add(new CharacterRule(EnglishCharacterData.UpperCase)); } if (!parameters.isExcludeLower()) { characterRules.add(new CharacterRule(EnglishCharacterData.LowerCase)); } return characterRules; } private  CharacterRuleProvider(); static List<CharacterRule> getCharacterRules(final StringGenerationParameters parameters);  }
@Test public void getCharacterRules_createdCharacterRulesFromDefaultParameters() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, containsInAnyOrder( usesCharacters(EnglishCharacterData.Digit), usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.UpperCase) )); assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.HEX)))); }
@Test public void getCharacterRules_canCreateCharacterRulesWithoutUppercase() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setExcludeUpper(true); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, iterableWithSize(2)); assertThat(characterRules, containsInAnyOrder( usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit) )); assertThat(characterRules, not(containsInAnyOrder( usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(CredHubCharacterData.SPECIAL), usesCharacters(CredHubCharacterData.HEX) ))); }
@Test public void getCharacterRules_canCreateCharacterRulesWithoutLowercase() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setExcludeLower(true); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, iterableWithSize(2)); assertThat(characterRules, containsInAnyOrder( usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(EnglishCharacterData.Digit) )); assertThat(characterRules, not(containsInAnyOrder( usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(CredHubCharacterData.SPECIAL), usesCharacters(CredHubCharacterData.HEX) ))); }
@Test public void getCharacterRules_canCreateCharacterRulesWithoutSpecialCharacters() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setIncludeSpecial(false); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, iterableWithSize(3)); assertThat(characterRules, containsInAnyOrder( usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit) )); assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.SPECIAL)))); assertThat(characterRules, not(hasItem(usesCharacters(CredHubCharacterData.HEX)))); }
@Test public void getCharacterRules_canCreateCharacterRulesWithAllIncluded() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setIncludeSpecial(true); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, iterableWithSize(4)); assertThat(characterRules, containsInAnyOrder( usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(EnglishCharacterData.LowerCase), usesCharacters(EnglishCharacterData.Digit), usesCharacters(CredHubCharacterData.SPECIAL) )); }
@Test public void getCharacterRules_canCreateCharacterRulesWithoutNumbers() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setExcludeNumber(true); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, iterableWithSize(2)); assertThat(characterRules, containsInAnyOrder( usesCharacters(EnglishCharacterData.UpperCase), usesCharacters(EnglishCharacterData.LowerCase) )); assertThat(characterRules, not(containsInAnyOrder( usesCharacters(EnglishCharacterData.Digit), usesCharacters(CredHubCharacterData.SPECIAL) ))); }
@Test public void getCharacterRules_returnsAnEmptyListWhenAllAreExcluded() { final StringGenerationParameters generationParameters = new StringGenerationParameters(); generationParameters.setIncludeSpecial(false); generationParameters.setExcludeNumber(true); generationParameters.setExcludeUpper(true); generationParameters.setExcludeLower(true); final List<CharacterRule> characterRules = CharacterRuleProvider .getCharacterRules(generationParameters); assertThat(characterRules, iterableWithSize(0)); }