### Question:
MdcTagFactory implements TagFactory { @Override public Tag createTag() { String value = MDC.get(name); return value != null ? new BasicTag(name, value) : null; } MdcTagFactory(String name); @Override String name(); @Override Tag createTag();  }### Answer:
@Test public void testNoValueInMdc() { TagFactory factory = new MdcTagFactory("unused"); Assertions.assertNull(factory.createTag()); }
@Test public void testValueInMdc() { String mdcName = "key"; String expectedValue = "value"; Tag expectedTag = new BasicTag(mdcName, expectedValue); TagFactory factory = new MdcTagFactory("key"); try (MDC.MDCCloseable closeable = MDC.putCloseable(mdcName, expectedValue)) { Tag actualTag = factory.createTag(); Assertions.assertEquals(expectedTag, actualTag); } Assertions.assertNull(factory.createTag()); }