PisPasepRegexValidatorService extends AbstractDocRegexValidatorService { @Override public String format(String pisPasep) { pisPasep = NON_DIGIT.matcher(pisPasep).replaceAll(""); StringBuilder builder = new StringBuilder(15); builder.append(pisPasep.substring(0, 3)).append("."); builder.append(pisPasep.substring(3, 8)).append("."); builder.append(pisPasep.substring(8, 10)).append("-"); builder.append(pisPasep.substring(10, 11)); return builder.toString(); }  @Override String format(String pisPasep); @Override List<String> getRegexNames();  }
@Test public void testFormatUnformattedPisPasep() { String pisPasep = "42313629124"; assertEquals("423.13629.12-4", service.format(pisPasep)); }
@Test public void testFormatPartiallyormattedPisPasep() { String cnpj = "4231362912-4"; assertEquals("423.13629.12-4", service.format(cnpj)); }