DnsCache implements Serializable { @Override public String toString() { return "DnsCache{" + "cache=" + cache + ", negativeCache=" + negativeCache + '}'; } DnsCache(List<DnsCacheEntry> cache, List<DnsCacheEntry> negativeCache); List<DnsCacheEntry> getCache(); List<DnsCacheEntry> getNegativeCache(); @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 entry1 = new DnsCacheEntry("a.com", new String[]{"1.1.1.1"}, expiration); DnsCacheEntry entry2 = new DnsCacheEntry("b.com", new String[]{"1.1.1.2"}, expiration); DnsCacheEntry entry3 = new DnsCacheEntry("c.com", new String[]{"1.1.1.2"}, expiration); DnsCache dnsCache = new DnsCache( Arrays.asList(entry1, entry2), Arrays.asList(entry3)); String expected = String.format("DnsCache{cache=[DnsCacheEntry{host='a.com', ips=[1.1.1.1], expiration=%s}" + ", DnsCacheEntry{host='b.com', ips=[1.1.1.2], expiration=%<s}]" + ", negativeCache=[DnsCacheEntry{host='c.com', ips=[1.1.1.2], expiration=%<s}]}", date); assertEquals(expected, dnsCache.toString()); }