Caller { @Pure public static Class<?> findClassForFirstCallerOutsideVmutilModule() { Class<?> type = getCaller().getCallerClass(1); int i = 3; while (type != null && MODULE_NAME.equals(type.getModule().getName())) { type = getCaller().getCallerClass(i); ++i; } return type; } private  Caller(); @Pure static org.arakhne.afc.vmutil.caller.Caller getCaller(); @Pure static String getCallerMethod(); @Pure static String getCallerMethod(int level); @Pure static Class<?> getCallerClass(); @Pure static Class<?> getCallerClass(int level); @Pure static Class<?> findClassForFirstCallerOutsideVmutilModule(); static final String MODULE_NAME; }
@Test public void findClassForFirstCallerOutsideVmutilModule() throws Exception { Class<?> expected = Caller.getCallerClass(); final Module module = CallerTest.class.getModule(); if (module != null && !Caller.MODULE_NAME.equals(module.getName())) { expected = CallerTest.class; } Class<?> c = Caller.findClassForFirstCallerOutsideVmutilModule(); assertEquals(expected, c); }