package org.jgrades.logging;

import com.project.StrangerClass;
import org.junit.Before;
import org.junit.Test;
import org.springframework.test.util.ReflectionTestUtils;

import static org.assertj.core.api.StrictAssertions.assertThat;

public class JgLoggerFactoryTest {
    @Before
    public void setUp() throws Exception {
        Class.forName("org.jgrades.logging.JgLoggerFactory");
    }

    @Test
    public void shouldSetJGradesModuleName_whenConstructWithJGradesClass() throws Exception {
        // given
        Class clazz = JgLoggerTest.class;

        // when
        JgLogger jgLogger = JgLoggerFactory.getLogger(clazz);

        // then
        String moduleName = (String) ReflectionTestUtils.getField(jgLogger, "moduleName");
        assertThat(moduleName).isEqualTo("logging");
    }

    @Test
    public void shouldSetExternalLibModuleName_whenConstructNotWithJGradesClass() throws Exception {
        // given
        Class clazz = StrangerClass.class;

        // when
        JgLogger jgLogger = JgLoggerFactory.getLogger(clazz);

        // then
        String moduleName = (String) ReflectionTestUtils.getField(jgLogger, "moduleName");
        assertThat(moduleName).isEqualTo("external-lib");
    }

}

@@ -268,132 +268,8 @@
 t %7B%0A
-    @Before%0A    public void setUp() throws Exception %7B%0A        Class.forName(%22org.jgrades.logging.JgLoggerFactory%22);%0A    %7D%0A%0A
     

remove before