CertificateIdentity { @Override public String toString() { return "{" + "domain:\"" + getDomain() + "\"" + ", service:\"" + getService() + "\"" + ", roles:[" + getRoles().stream().map(r -> '"' + r + '"').collect(Collectors.joining(", ")) + "]" + ", x509Cert:\"" + getX509Certificate().toString() + "\"" + "}"; } CertificateIdentity(String domain, String service, List<String> roles, X509Certificate x509Certificate); String getPrincipalName(); String getDomain(); String getService(); List<String> getRoles(); X509Certificate getX509Certificate(); @Override String toString();  }
@Test public void testToString() throws Exception { X509Certificate cert = this.readCert("valid_cn_x509.cert"); CertificateIdentity certId = new CertificateIdentity("domain", "service", Arrays.asList("role_1", "role_2"), cert); assertNotNull(certId); assertEquals(certId.toString(), String.format("{domain:\"domain\", service:\"service\", roles:[\"role_1\", \"role_2\"], x509Cert:\"%s\"}", certId.getX509Certificate().toString())); }