JavaAgent { public static void premain(String options, Instrumentation instrumentation) { init(options, instrumentation, false); }  static void premain(String options, Instrumentation instrumentation); static void agentmain(String options, Instrumentation instrumentation); static long sizeOf(Object o); static Instrumentation getInstrumentation(); static Class<?> findClass(String className); static Class<?> findClass(String className, final ClassLoader classLoader); static Class<?> findClass(Class<?>[] classes, String className); static List<Class<?>> findClassList(String className); static List<Class<?>> findClassList(Class<?>[] classes, String className); static Class<?>[] getAllLoadedClasses(); static Class<?>[] getSystemClassLoaderInitiatedClasses(); static Class<?>[] getClassLoaderInitiatedClasses(final ClassLoader classLoader); static boolean redefineClasses(ClassDefinition[] classDefinitions); static boolean redefineClasses(Class<?> clazz, byte[] buff); static boolean isRedefineClassesSupported();  }
@Test public void testDuplicateInitializeCalls() { assertThat(JavaAgent.STATUS.get(), is(false)); Instrumentation instrumentation = mock(Instrumentation.class); JavaAgent.premain("agent.class.path=", instrumentation); for (int i = 0; i < 3; i++) { assertThat(JavaAgent.STATUS.get(), is(true)); if (!JavaAgent.STATUS.get()) { JavaAgent.premain("agent.class.path=", instrumentation); fail(); } } }