### Question:
InheritingMetadataContainer implements MetadataContainer { @Override public MetadataValue put(MetadataKey key, MetadataValue value) { Validate.notNull(key, "Metadata key is null"); Validate.notNull(value, "Metadata value is null"); validateKeyAcceptable(key); MetadataValue oldValue; Map<VersionIgnoringKeyWrapper, MetadataValue> metadata = container.get(key.getVersion()); if (metadata == null) { metadata = new HashMap<>(); container.put(key.getVersion(), metadata); receiveAllInheritance(key.getVersion(), metadata); } VersionIgnoringKeyWrapper keyWrapper = new VersionIgnoringKeyWrapper(key); oldValue = metadata.get(keyWrapper); if (oldValue != null) { metadata.remove(keyWrapper); } metadata.put(keyWrapper, value); if (!Objects.equals(value, oldValue)) { giveInheritance(key.getVersion(), keyWrapper, value); } return oldValue; } InheritingMetadataContainer(String subject); @Override String getSubject(); @Override Map<MetadataKey, MetadataValue> getCollection(int version); @Override MetadataValue get(MetadataKey key); @Override MetadataValue put(MetadataKey key, MetadataValue value); @Override MetadataValue remove(MetadataKey key); @Override boolean isEmpty();  }### Answer:
@Test public void testPut1() { MetadataKey key1 = new FieldMetadataKey("s", 1, "sfn", "f1"); MetadataKey key4 = new FieldMetadataKey("s", 4, "sfn", "f1"); MetadataValue value1 = MetadataValue.builder(). doc("doc1"). attributes(null). updatedAt(new Date()). updatedBy("me"). build(); MetadataValue value4 = MetadataValue.builder(). doc("doc4"). attributes(null). updatedAt(new Date()). updatedBy("me"). build(); InheritingMetadataContainer container = new InheritingMetadataContainer("s"); MetadataValue old1 = container.put(key1, value1); MetadataValue old4 = container.put(key4, value4); Assert.assertNull(old1); Assert.assertEquals(old4, value1); }
@Test public void testPut2() { MetadataKey key1 = new FieldMetadataKey("s", 1, "sfn", "f1"); MetadataKey key4 = new FieldMetadataKey("s", 1, "sfn", "f1"); MetadataValue value1 = MetadataValue.builder(). doc("doc1"). attributes(null). updatedAt(new Date()). updatedBy("me"). build(); MetadataValue value4 = MetadataValue.builder(). doc("doc4"). attributes(null). updatedAt(new Date()). updatedBy("me"). build(); InheritingMetadataContainer container = new InheritingMetadataContainer("s"); MetadataValue old1 = container.put(key1, value1); MetadataValue old4 = container.put(key4, value4); Assert.assertNull(old1); Assert.assertEquals(old4, value1); }