DnsCacheEntry implements Serializable { @Override public String toString() { final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); return "DnsCacheEntry{" + "host='" + host + '\'' + ", ips=" + Arrays.toString(ips) + ", expiration=" + dateFormat.format(expiration) + '}'; } DnsCacheEntry(String host, String[] ips, Date expiration); String getHost(); String[] getIps(); String getIp(); Date getExpiration(); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void test_toString() throws Exception { final Date expiration = new Date(); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); final String date = dateFormat.format(expiration); DnsCacheEntry entry = new DnsCacheEntry("a.com", new String[]{"1.1.1.1"}, expiration); String expected = String.format("DnsCacheEntry{host='a.com', ips=[1.1.1.1], expiration=%s}", date); assertEquals(expected, entry.toString()); }