### Question:
DiagnosticContext { public Map<String, String> getContext() { return context; } DiagnosticContext(DiagnosticContextSupplier supplier); Map<String, String> getContext(); void printContextInformation(StringBuilder result);  }### Answer:
@Test public void constructor_shouldCreateAnUnmodifiableMap() throws Exception { Map<String, String> expectedContext = new LinkedHashMap<>(); expectedContext.put("foo", "bar"); Map<String, String> actualContext = new DiagnosticContext(() -> expectedContext).getContext(); ensureUnmodifiableMap(actualContext); }
@Test public void constructor_shouldCreateAnEmptyContext_givenANullProvider() throws Exception { assertEquals(emptyMap(), new DiagnosticContext(null).getContext()); }
@Test public void constructor_shouldCreateAnEmptyContext_givenAProviderThatReturnsNull() throws Exception { assertEquals(emptyMap(), new DiagnosticContext(() -> null).getContext()); }
@Test public void constructor_shouldSafelyCopyTheProvidedContextInformationIntoANewMap() throws Exception { Map<String, String> expectedContext = new HashMap<>(); expectedContext.put("baker", "a"); expectedContext.put("able", "a"); expectedContext.put("charlie", "a"); Map<String, String> actualContext = new DiagnosticContext(() -> expectedContext).getContext(); assertNotSame(expectedContext, actualContext); assertEquals(expectedContext, actualContext); expectedContext.clear(); assertNotEquals(expectedContext, actualContext); }