@Test
  public void testHashMap() throws Exception {
    Random random = getRandom();
    HashMap<Long, String> map = new HashMap<>();
    int size = random.nextInt(50);
    for (int i = 0; i < size; i++) {
      Long key = random.nextLong();
      String value = String.valueOf(random.nextLong());
      map.put(key, value);
    }

    DataOutputStream out = getDataOutput();
    DataSerializer.writeHashMap(map, out);
    out.flush();

    DataInput in = getDataInput();
    HashMap<Long, String> map2 = DataSerializer.readHashMap(in);
    assertEquals(map, map2);
  }
Tests data serializing an {@link HashMap}
geode-core/src/test/java/org/apache/geode/internal/DataSerializableJUnitTest.java