### Question:
Document implements Map<String, Object>, Bson { public Document cloneDeeply() { return cloneDeeply(this); } Document();  Document(String key, Object value);  Document(Map<String, ?> map); void cloneInto(Document targetDocument); Document cloneDeeply(); Document append(String key, Object value); Document appendAll(Map<String, Object> map); @Override boolean containsValue(Object value); @Override Object get(Object key); Object getOrMissing(Object key); @Override void clear(); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object key); @Override Object put(String key, Object value); void putIfNotNull(String key, Object value); @Override void putAll(Map<? extends String, ?> m); @Override Object remove(Object key); @Override @SuppressWarnings("unchecked") Document clone(); @Override Set<String> keySet(); @Override Collection<Object> values(); @Override Set<Entry<String, Object>> entrySet(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); String toString(boolean compactKey); String toString(boolean compactKey, String prefix, String suffix);  }### Answer:
@Test void testCloneDeeply() throws Exception { Document original = new Document(); original.put("subDocument", new Document("_id", 1)); original.put("sub", new Document("sub", Arrays.asList(1, new Document("key", "value"), 3))); original.put("null-value", null); original.put("set", new LinkedHashSet<>()); String originalToString = "{\"subDocument\" : {\"_id\" : 1}, \"sub\" : {\"sub\" : [ 1, { \"key\" : \"value\" }, 3 ]}, \"null-value\" : null, \"set\" : []}"; assertThat(original).hasToString(originalToString); Document deepClone = original.cloneDeeply(); assertThat(deepClone) .isNotSameAs(original) .isEqualTo(original); assertThat(deepClone).hasToString(original.toString()); Utils.changeSubdocumentValue(deepClone, "sub.sub.1", 25); Utils.changeSubdocumentValue(deepClone, "subDocument._id", 2); deepClone.remove("null-value"); ((Collection<Object>) deepClone.get("set")).add("more"); assertThat(deepClone).hasToString("{\"subDocument\" : {\"_id\" : 2}, \"sub\" : {\"sub\" : [ 1, 25, 3 ]}, \"set\" : [ \"more\" ]}"); assertThat(original).hasToString(originalToString); }