TextPatternUtil { public static Integer replaceCharacter(Integer codePointToReplace, Random random) { for (CharPattern charPattern : CharPattern.values()) { if (charPattern.contains(codePointToReplace)) { int length = charPattern.getCodePointSize(); int position = random.nextInt(length); return charPattern.getCodePointAt(position); } } return codePointToReplace; } private  TextPatternUtil(); static String findPattern(String stringToRecognize); static Integer replaceCharacter(Integer codePointToReplace, Random random); static List<Integer> replaceStringCodePoints(String stringToReplace, Random random); static char[] replacePatternCharacter(Integer codePointToReplace, Random random); static Set<CharPattern> getCharPatterns(List<Integer> codePoints, List<Integer> filteredCodepoints); static CharPattern getCharPattern(Integer codepoint); static final int PROLONGED_SOUND_MARK; }
@Test public void replaceUnrecognizedCharacters() { Random random = new Random(); String input = "@&+-/_"; for (int i = 0; i < input.length(); i++) { Integer codePoint = input.codePointAt(i); Integer replaceCodePoint = TextPatternUtil.replaceCharacter(codePoint, random); String errorMessage = "Character " + input.charAt(i) + " does not have the codepoint " + replaceCodePoint; assertSame(errorMessage, codePoint, replaceCodePoint); } }