Logger { public String getName() { return slf4jLogger.getName(); } private  Logger(String name); @VisibleForTesting  Logger(org.slf4j.Logger logger); static Logger getLogger(String name); static Logger getLogger(String name,
            @SuppressWarnings("unused") String resourceBundleName); String getName(); void severe(String msg); void warning(String msg); void info(String msg); void config(String msg); void fine(String msg); void finer(String msg); void finest(String msg); void log(LogRecord record); void log(Level level, String msg); void log(Level level, String msg, @Nullable Object param1); void log(Level level, String msg, @Nullable Object[] params); void log(Level level, String msg, Throwable thrown); boolean isLoggable(Level level); Level getLevel(); @SuppressWarnings("unused") void logp(Level level, String sourceClass, String sourceMethod, String msg); @SuppressWarnings("unused") void logp(Level level, String sourceClass, String sourceMethod, String msg,
            Object param1); @SuppressWarnings("unused") void logp(Level level, String sourceClass, String sourceMethod, String msg,
            Object[] params); @SuppressWarnings("unused") void logp(Level level, String sourceClass, String sourceMethod, String msg,
            Throwable thrown); @SuppressWarnings("unused") void logrb(Level level, String sourceClass, String sourceMethod, String bundleName,
            String msg); @SuppressWarnings("unused") void logrb(Level level, String sourceClass, String sourceMethod, String bundleName,
            String msg, Object param1); @SuppressWarnings("unused") void logrb(Level level, String sourceClass, String sourceMethod, String bundleName,
            String msg, Object[] params); @SuppressWarnings("unused") void logrb(Level level, String sourceClass, String sourceMethod, ResourceBundle bundle,
            String msg, Object... params); @SuppressWarnings("unused") void logrb(Level level, ResourceBundle bundle, String msg, Object... params); @SuppressWarnings("unused") void logrb(Level level, String sourceClass, String sourceMethod, String bundleName,
            String msg, Throwable thrown); @SuppressWarnings("unused") void logrb(Level level, String sourceClass, String sourceMethod, ResourceBundle bundle,
            String msg, Throwable thrown); @SuppressWarnings("unused") void logrb(Level level, ResourceBundle bundle, String msg, Throwable thrown); @SuppressWarnings("unused") void entering(String sourceClass, String sourceMethod); @SuppressWarnings("unused") void entering(String sourceClass, String sourceMethod, Object param1); @SuppressWarnings("unused") void entering(String sourceClass, String sourceMethod, Object[] params); @SuppressWarnings("unused") void exiting(String sourceClass, String sourceMethod); @SuppressWarnings("unused") void exiting(String sourceClass, String sourceMethod, Object result); @SuppressWarnings("unused") void throwing(String sourceClass, String sourceMethod, Throwable thrown); @Nullable ResourceBundle getResourceBundle(); void setResourceBundle(ResourceBundle resourceBundle); @Nullable String getResourceBundleName(); Logger getParent(); void setParent(@SuppressWarnings("unused") Logger parent); void setLevel(@SuppressWarnings("unused") Level newLevel); static Logger getAnonymousLogger(); static Logger getAnonymousLogger(@SuppressWarnings("unused") String resourceBundleName); static final Logger getGlobal(); static final String GLOBAL_LOGGER_NAME; static final Logger global; }
@Test public void testImplementsAllMethods() { Set<MethodSignature> glowrootLoggerMethods = Sets.newHashSet(); for (Method method : Logger.class.getMethods()) { ImmutableMethodSignature.Builder builder = ImmutableMethodSignature.builder() .name(method.getName()); for (Class<?> clazz : method.getParameterTypes()) { String parameterType = clazz.getName(); builder.addParameterTypes(parameterType.replaceFirst("org.glowroot.agent.jul.", "java.util.logging.")); } glowrootLoggerMethods.add(builder .returnType(method.getReturnType().getName() .replaceFirst("org.glowroot.agent.jul.", "java.util.logging.")) .build()); } Set<MethodSignature> loggerMethods = Sets.newHashSet(); for (Method method : java.util.logging.Logger.class.getMethods()) { String methodName = method.getName(); if (methodName.contains("Handler") || methodName.contains("Filter")) { continue; } ImmutableMethodSignature.Builder builder = ImmutableMethodSignature.builder() .name(methodName); List<String> parameterTypes = Lists.newArrayList(); for (Class<?> clazz : method.getParameterTypes()) { parameterTypes.add(clazz.getName()); } if (parameterTypes.contains("java.util.function.Supplier")) { continue; } loggerMethods.add(builder .addAllParameterTypes(parameterTypes) .returnType(method.getReturnType().getName()) .build()); } assertThat(glowrootLoggerMethods).containsAll(loggerMethods); }
@Test public void testGetName() { org.slf4j.Logger slf4jLogger = mock(org.slf4j.Logger.class); when(slf4jLogger.getName()).thenReturn("xyz"); Logger logger = new Logger(slf4jLogger); assertThat(logger.getName()).isEqualTo("xyz"); }