### Question:
ByteBuddyAgent { public static Instrumentation getInstrumentation() { Instrumentation instrumentation = doGetInstrumentation(); if (instrumentation == null) { throw new IllegalStateException("The Byte Buddy agent is not initialized"); } return instrumentation; } private  ByteBuddyAgent(); static Instrumentation getInstrumentation(); static void attach(File agentJar, String processId); static void attach(File agentJar, String processId, String argument); static void attach(File agentJar, String processId, AttachmentProvider attachmentProvider); static void attach(File agentJar, String processId, String argument, AttachmentProvider attachmentProvider); static void attach(File agentJar, ProcessProvider processProvider); static void attach(File agentJar, ProcessProvider processProvider, String argument); static void attach(File agentJar, ProcessProvider processProvider, AttachmentProvider attachmentProvider); static void attach(File agentJar, ProcessProvider processProvider, String argument, AttachmentProvider attachmentProvider); static void attachNative(File agentLibrary, String processId); static void attachNative(File agentLibrary, String processId, String argument); static void attachNative(File agentLibrary, String processId, AttachmentProvider attachmentProvider); static void attachNative(File agentLibrary, String processId, String argument, AttachmentProvider attachmentProvider); static void attachNative(File agentLibrary, ProcessProvider processProvider); static void attachNative(File agentLibrary, ProcessProvider processProvider, String argument); static void attachNative(File agentLibrary, ProcessProvider processProvider, AttachmentProvider attachmentProvider); static void attachNative(File agentLibrary, ProcessProvider processProvider, String argument, AttachmentProvider attachmentProvider); static Instrumentation install(); static Instrumentation install(AttachmentProvider attachmentProvider); static Instrumentation install(ProcessProvider processProvider); static synchronized Instrumentation install(AttachmentProvider attachmentProvider, ProcessProvider processProvider); static final String LATENT_RESOLVE; }### Answer:
@Test public void testInstrumentationExtraction() throws Exception { Field field = Installer.class.getDeclaredField(INSTRUMENTATION); field.setAccessible(true); Instrumentation instrumentation = mock(Instrumentation.class); field.set(STATIC_FIELD, instrumentation); assertThat(ByteBuddyAgent.getInstrumentation(), is(instrumentation)); }
@Test(expected = IllegalStateException.class) public void testMissingInstrumentationThrowsException() throws Exception { Field field = Installer.class.getDeclaredField(INSTRUMENTATION); field.setAccessible(true); field.set(STATIC_FIELD, null); ByteBuddyAgent.getInstrumentation(); }