DefaultContentMetadata implements ContentMetadata { @Override @Nullable public final byte[] get(String name, @Nullable byte[] defaultValue) { if (metadata.containsKey(name)) { byte[] bytes = metadata.get(name); return Arrays.copyOf(bytes, bytes.length); } else { return defaultValue; } } DefaultContentMetadata();  DefaultContentMetadata(Map<String, byte[]> metadata); DefaultContentMetadata copyWithMutationsApplied(ContentMetadataMutations mutations); Set<Entry<String, byte[]>> entrySet(); @Override @Nullable final byte[] get(String name, @Nullable byte[] defaultValue); @Override @Nullable final String get(String name, @Nullable String defaultValue); @Override final long get(String name, long defaultValue); @Override final boolean contains(String name); @Override boolean equals(@Nullable Object o); @Override int hashCode(); static final DefaultContentMetadata EMPTY; }
@Test public void testGetReturnsDefaultValueWhenValueIsNotAvailable() throws Exception { assertThat(contentMetadata.get("metadata name", "default value")).isEqualTo("default value"); }
@Test public void testGetReturnsInitialValue() throws Exception { contentMetadata = createContentMetadata("metadata name", "value"); assertThat(contentMetadata.get("metadata name", "default value")).isEqualTo("value"); }
@Test public void testNewMetadataNotWrittenBeforeCommitted() throws Exception { ContentMetadataMutations mutations = new ContentMetadataMutations(); mutations.set("metadata name", "value"); assertThat(contentMetadata.get("metadata name", "default value")).isEqualTo("default value"); }