package org.xbib.logging.log4j.test;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.message.StringFormatterMessageFactory;
import org.apache.logging.log4j.spi.LoggerContext;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class LoggerContextTest extends AbstractTest {

    @Test
    public void testHasLogger() {
        final LoggerContext loggerContext = LogManager.getContext();
        final Logger logger = LogManager.getFormatterLogger(LoggerTest.class);
        assertFalse(loggerContext.hasLogger("org.xbib.logging"));
        assertFalse(loggerContext.hasLogger(logger.getName()));
        assertTrue(loggerContext.hasLogger(logger.getName(), StringFormatterMessageFactory.INSTANCE));
        assertTrue(loggerContext.hasLogger(logger.getName(), StringFormatterMessageFactory.class));
    }

    @Test
    public void testExternalContext() {
        final Object externalContext = new Object();
        final LoggerContext loggerContext = LogManager.getContext(LoggerContextTest.class.getClassLoader(), true,
                externalContext);
        assertEquals(externalContext, loggerContext.getExternalContext());
    }
}
