Host { @Override public int hashCode() { initHash(); return hash; } private  Host(); private  Host(Builder builder); ImmutableSortedMap<String, String> properties(); @Override boolean equals(Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void hash() { int expected = PersistentHashing.getPersistentHashFunction() .newHasher() .putObject(ImmutableMap.of("a", "1", "b", "2"), StringMapFunnel.INSTANCE) .hash() .asInt(); Host host = new Host.Builder().addProperty("a", "1").addProperty("b", "2").build(); assertEquals(expected, host.hashCode()); }
@Test public void hash_afterJsonSerialization() { int expected = PersistentHashing.getPersistentHashFunction() .newHasher() .putObject(ImmutableMap.of("a", "1", "b", "2"), StringMapFunnel.INSTANCE) .hash() .asInt(); Host host = new Host.Builder().addProperty("a", "1").addProperty("b", "2").build(); Gson gson = DaggerHostTest_GsonComponent.create().gson(); assertEquals(expected, gson.fromJson(gson.toJson(host), Host.class).hashCode()); }