Cluster { @Override public String toString() { return "Cluster{" + "id=" + id + ", name='" + name + '\'' + ", brokerHosts='" + brokerHosts + '\'' + ", isSslEnabled=" + isSslEnabled + ", trustStoreFile='" + trustStoreFile + '\'' + ", keyStoreFile='" + keyStoreFile + '\'' + ", isSaslEnabled=" + isSaslEnabled + ", saslMechanism='" + saslMechanism + '\'' + ", isValid=" + isValid + '}'; }  long getId(); void setId(final long id); String getName(); void setName(final String name); String getBrokerHosts(); void setBrokerHosts(final String brokerHosts); String getOptionParameters(); void setOptionParameters(final String optionParameters); boolean isSslEnabled(); void setSslEnabled(final boolean useSsl); String getTrustStoreFile(); void setTrustStoreFile(final String trustStoreFile); String getTrustStorePassword(); void setTrustStorePassword(final String trustStorePassword); String getKeyStoreFile(); void setKeyStoreFile(final String keyStoreFile); String getKeyStorePassword(); void setKeyStorePassword(final String keyStorePassword); boolean isValid(); void setValid(final boolean valid); boolean isSaslEnabled(); void setSaslEnabled(final boolean saslEnabled); String getSaslMechanism(); void setSaslMechanism(final String saslMechanism); String getSaslConfig(); void setSaslConfig(final String saslConfig); @Override String toString();  }
@Test public void testToString() throws IllegalAccessException, NoSuchFieldException { final String expectedSecret1 = "MySuperSecretKey"; final String expectedSecret2 = "AnotherSecret"; final Cluster cluster = new Cluster(); final Field field1 = cluster.getClass().getDeclaredField("trustStorePassword"); field1.setAccessible(true); field1.set(cluster, expectedSecret1); final Field field2 = cluster.getClass().getDeclaredField("keyStorePassword"); field2.setAccessible(true); field2.set(cluster, expectedSecret1); final String result = cluster.toString(); assertFalse("Should not contain our sensitive field", result.contains(expectedSecret1)); assertFalse("Should not contain our sensitive field", result.contains(expectedSecret2)); }