Home / Class/ Slf4JLoggerFactoryTest Class — netty Architecture

Slf4JLoggerFactoryTest Class — netty Architecture

Architecture documentation for the Slf4JLoggerFactoryTest class in Slf4JLoggerFactoryTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  9f925406_7438_c14f_71a3_389088c21656["Slf4JLoggerFactoryTest"]
  5b786213_a0cc_67b6_d3bc_a90d04ec52f9["Slf4JLoggerFactoryTest.java"]
  9f925406_7438_c14f_71a3_389088c21656 -->|defined in| 5b786213_a0cc_67b6_d3bc_a90d04ec52f9
  f71febac_9a7d_b0b9_ab5a_80fa0c2e06b6["testCreation()"]
  9f925406_7438_c14f_71a3_389088c21656 -->|method| f71febac_9a7d_b0b9_ab5a_80fa0c2e06b6
  682e7434_a813_03b8_d5ae_08bbb05eea6b["testCreationLogger()"]
  9f925406_7438_c14f_71a3_389088c21656 -->|method| 682e7434_a813_03b8_d5ae_08bbb05eea6b
  294420de_c8fa_0b36_70d1_77a1d5d48849["testCreationLocationAwareLogger()"]
  9f925406_7438_c14f_71a3_389088c21656 -->|method| 294420de_c8fa_0b36_70d1_77a1d5d48849
  cfbd0e56_3dc5_613d_d403_72ccfd1c2d43["testFormatMessage()"]
  9f925406_7438_c14f_71a3_389088c21656 -->|method| cfbd0e56_3dc5_613d_d403_72ccfd1c2d43

Relationship Graph

Source Code

common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java lines 32–125

public class Slf4JLoggerFactoryTest {

    @Test
    public void testCreation() {
        InternalLogger logger = Slf4JLoggerFactory.INSTANCE.newInstance("foo");
        assertTrue(logger instanceof Slf4JLogger || logger instanceof LocationAwareSlf4JLogger);
        assertEquals("foo", logger.name());
    }

    @Test
    public void testCreationLogger() {
        Logger logger = mock(Logger.class);
        when(logger.getName()).thenReturn("testlogger");
        InternalLogger internalLogger = Slf4JLoggerFactory.wrapLogger(logger);
        assertTrue(internalLogger instanceof Slf4JLogger);
        assertEquals("testlogger", internalLogger.name());
    }

    @Test
    public void testCreationLocationAwareLogger() {
        Logger logger = mock(LocationAwareLogger.class);
        when(logger.getName()).thenReturn("testlogger");
        InternalLogger internalLogger = Slf4JLoggerFactory.wrapLogger(logger);
        assertTrue(internalLogger instanceof LocationAwareSlf4JLogger);
        assertEquals("testlogger", internalLogger.name());
    }

    @Test
    public void testFormatMessage() {
        ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
        LocationAwareLogger logger = mock(LocationAwareLogger.class);
        when(logger.isDebugEnabled()).thenReturn(true);
        when(logger.isErrorEnabled()).thenReturn(true);
        when(logger.isInfoEnabled()).thenReturn(true);
        when(logger.isTraceEnabled()).thenReturn(true);
        when(logger.isWarnEnabled()).thenReturn(true);
        when(logger.getName()).thenReturn("testlogger");

        InternalLogger internalLogger = Slf4JLoggerFactory.wrapLogger(logger);
        internalLogger.debug("{}", "debug");
        internalLogger.debug("{} {}", "debug1", "debug2");
        internalLogger.debug("{} {} {}", "debug1", "debug2", "debug3");

        internalLogger.error("{}", "error");
        internalLogger.error("{} {}", "error1", "error2");
        internalLogger.error("{} {} {}", "error1", "error2", "error3");

        internalLogger.info("{}", "info");
        internalLogger.info("{} {}", "info1", "info2");
        internalLogger.info("{} {} {}", "info1", "info2", "info3");

        internalLogger.trace("{}", "trace");
        internalLogger.trace("{} {}", "trace1", "trace2");
        internalLogger.trace("{} {} {}", "trace1", "trace2", "trace3");

        internalLogger.warn("{}", "warn");
        internalLogger.warn("{} {}", "warn1", "warn2");
        internalLogger.warn("{} {} {}", "warn1", "warn2", "warn3");

        verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN),
                eq(LocationAwareLogger.DEBUG_INT), captor.capture(), ArgumentMatchers.<Object[]>isNull(),
                ArgumentMatchers.<Throwable>isNull());
        verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN),
                eq(LocationAwareLogger.ERROR_INT), captor.capture(), ArgumentMatchers.<Object[]>isNull(),
                ArgumentMatchers.<Throwable>isNull());
        verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN),
                eq(LocationAwareLogger.INFO_INT), captor.capture(), ArgumentMatchers.<Object[]>isNull(),
                ArgumentMatchers.<Throwable>isNull());
        verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN),
                eq(LocationAwareLogger.TRACE_INT), captor.capture(), ArgumentMatchers.<Object[]>isNull(),
                ArgumentMatchers.<Throwable>isNull());
        verify(logger, times(3)).log(ArgumentMatchers.<Marker>isNull(), eq(LocationAwareSlf4JLogger.FQCN),
                eq(LocationAwareLogger.WARN_INT), captor.capture(), ArgumentMatchers.<Object[]>isNull(),
                ArgumentMatchers.<Throwable>isNull());

        Iterator<String> logMessages = captor.getAllValues().iterator();
        assertEquals("debug", logMessages.next());
        assertEquals("debug1 debug2", logMessages.next());
        assertEquals("debug1 debug2 debug3", logMessages.next());
        assertEquals("error", logMessages.next());
        assertEquals("error1 error2", logMessages.next());

Frequently Asked Questions

What is the Slf4JLoggerFactoryTest class?
Slf4JLoggerFactoryTest is a class in the netty codebase, defined in common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java.
Where is Slf4JLoggerFactoryTest defined?
Slf4JLoggerFactoryTest is defined in common/src/test/java/io/netty/util/internal/logging/Slf4JLoggerFactoryTest.java at line 32.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free