### Question:
DCRContextImplementation implements DCRContext { public static DCRContextImplementation create(Logger logger) { final Instrumentation instrumentation = ExposeInstrumentation.getInstrumentation(); try { final Method m = Instrumentation.class.getMethod("isRetransformClassesSupported"); if (!(Boolean)m.invoke(instrumentation)) { logger.info( "Java VM does not support class retransformation, DCR unavailable"); return null; } } catch (Exception e1) { logger.info("Java VM does not support instrumentation, DCR unavailable"); return null; } return new DCRContextImplementation(instrumentation, RecorderLocator.class, RecorderLocator.getRecorderRegistry()); } DCRContextImplementation(Instrumentation instrumentation,
                           Class<?> recorderLocatorClass,
                           RecorderRegistry recorderRegistry); static DCRContextImplementation create(Logger logger); @Override void add(Object target,
                            Constructor<?> constructor,
                            Recorder recorder); @Override void add(Object target,
                            Method method,
                            TargetSource targetSource,
                            Recorder recorder); @Override boolean isInstrumentable(Class<?> targetClass); @Override void applyChanges();  }### Answer:
@Test public void testCreateWithNoInstrumentation() throws Exception { ExposeInstrumentation.premain("", null); assertNull(DCRContextImplementation.create(m_logger)); verify(m_logger).info(contains("does not support")); verifyNoMoreInteractions(m_logger); }
@Test public void testCreateWithNoRetransformation() throws Exception { ExposeInstrumentation.premain("", m_instrumentation); when(m_instrumentation.isRetransformClassesSupported()).thenReturn(false); assertNull(DCRContextImplementation.create(m_logger)); verify(m_logger).info(contains("does not support")); verifyNoMoreInteractions(m_logger); }
@Test public void testCreateWithBadRetransformation() throws Exception { ExposeInstrumentation.premain("", m_instrumentation); when(m_instrumentation.isRetransformClassesSupported()) .thenThrow(new NoSuchMethodError()); assertNull(DCRContextImplementation.create(m_logger)); verify(m_logger).info(contains("does not support")); verifyNoMoreInteractions(m_logger); }