PlcUsernamePasswordAuthentication implements PlcAuthentication { @Override public String toString() { return "PlcUsernamePasswordAuthentication{" + "username='" + username + '\'' + ", password='" + "*****************" + '\'' + '}'; } PlcUsernamePasswordAuthentication(String username, String password); String getUsername(); String getPassword(); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString();  }
@Test public void toStringDoesntLeakPassword() { PlcUsernamePasswordAuthentication authentication = new PlcUsernamePasswordAuthentication("user", "top-secret"); assertThat(authentication.toString(), Matchers.not(Matchers.containsString("top-secret"))); }