@Test public void testFormatCPF() { String cpf = "57042882008"; String formatted = "570.428.820-08"; String result = service.format(cpf); assertEquals(formatted, result); }
@Override public String format(String cpf) { cpf = NON_DIGIT.matcher(cpf).replaceAll(""); StringBuilder builder = new StringBuilder(15); builder.append(cpf.substring(0, 3)).append("."); builder.append(cpf.substring(3, 6)).append("."); builder.append(cpf.substring(6, 9)).append("-"); builder.append(cpf.substring(9, 11)); return builder.toString(); }
CPFRegexValidatorService extends AbstractDocRegexValidatorService { @Override public String format(String cpf) { cpf = NON_DIGIT.matcher(cpf).replaceAll(""); StringBuilder builder = new StringBuilder(15); builder.append(cpf.substring(0, 3)).append("."); builder.append(cpf.substring(3, 6)).append("."); builder.append(cpf.substring(6, 9)).append("-"); builder.append(cpf.substring(9, 11)); return builder.toString(); } }
CPFRegexValidatorService extends AbstractDocRegexValidatorService { @Override public String format(String cpf) { cpf = NON_DIGIT.matcher(cpf).replaceAll(""); StringBuilder builder = new StringBuilder(15); builder.append(cpf.substring(0, 3)).append("."); builder.append(cpf.substring(3, 6)).append("."); builder.append(cpf.substring(6, 9)).append("-"); builder.append(cpf.substring(9, 11)); return builder.toString(); }  }
CPFRegexValidatorService extends AbstractDocRegexValidatorService { @Override public String format(String cpf) { cpf = NON_DIGIT.matcher(cpf).replaceAll(""); StringBuilder builder = new StringBuilder(15); builder.append(cpf.substring(0, 3)).append("."); builder.append(cpf.substring(3, 6)).append("."); builder.append(cpf.substring(6, 9)).append("-"); builder.append(cpf.substring(9, 11)); return builder.toString(); }  @Override String format(String cpf); @Override List<String> getRegexNames(); }
CPFRegexValidatorService extends AbstractDocRegexValidatorService { @Override public String format(String cpf) { cpf = NON_DIGIT.matcher(cpf).replaceAll(""); StringBuilder builder = new StringBuilder(15); builder.append(cpf.substring(0, 3)).append("."); builder.append(cpf.substring(3, 6)).append("."); builder.append(cpf.substring(6, 9)).append("-"); builder.append(cpf.substring(9, 11)); return builder.toString(); }  @Override String format(String cpf); @Override List<String> getRegexNames();  }