@ -16,15 +16,14 @@
package org.springframework.boot.autoconfigure.logging ;
import java.lang.reflect.Field ;
import java.util.ArrayList ;
import java.util.List ;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.LogConfigurationException ;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.logging.impl.LogFactoryImpl ;
import org.apache.commons.logging.impl.NoOpLog ;
import org.apache.commons.logging.impl.SLF4JLogFactory ;
import org.junit.After ;
import org.junit.Before ;
import org.junit.Test ;
@ -42,7 +41,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import ;
import org.springframework.context.event.ContextRefreshedEvent ;
import org.springframework.mock.web.MockServletContext ;
import org.springframework.util.ReflectionUtils ;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext ;
import static org.hamcrest.Matchers.containsString ;
@ -58,7 +56,7 @@ import static org.mockito.Mockito.mock;
/ * *
* Tests for { @link AutoConfigurationReportLoggingInitializer } .
*
*
* @author Phillip Webb
* /
public class AutoConfigurationReportLoggingInitializerTests {
@ -73,10 +71,6 @@ public class AutoConfigurationReportLoggingInitializerTests {
protected List < String > infoLog = new ArrayList < String > ( ) ;
private Field logFactoryField ;
private LogFactory originalLogFactory ;
@Before
public void setup ( ) {
setupLogging ( true , true ) ;
@ -104,25 +98,15 @@ public class AutoConfigurationReportLoggingInitializerTests {
}
} ) . given ( this . log ) . info ( anyObject ( ) ) ;
try {
this . logFactoryField = LogFactory . class . getDeclaredField ( "logFactory" ) ;
ReflectionUtils . makeAccessible ( this . logFactoryField ) ;
this . originalLogFactory = ( LogFactory ) ReflectionUtils . getField (
this . logFactoryField , null ) ;
ReflectionUtils . setField ( this . logFactoryField , null , new MockLogFactory ( ) ) ;
}
catch ( Exception ex ) {
throw new IllegalStateException ( "Failed to set logFactory" , ex ) ;
}
LogFactory . releaseAll ( ) ;
System . setProperty ( LogFactory . FACTORY_PROPERTY , MockLogFactory . class . getName ( ) ) ;
this . initializer = new AutoConfigurationReportLoggingInitializer ( ) ;
}
@After
public void cleanup ( ) {
ReflectionUtils . setField ( this . logFactoryField , null , this . originalLogFactory ) ;
System . clearProperty ( LogFactory . FACTORY_PROPERTIES ) ;
LogFactory . releaseAll ( ) ;
}
@Test
@ -215,7 +199,7 @@ public class AutoConfigurationReportLoggingInitializerTests {
containsString ( "Unable to provide auto-configuration report" ) ) ;
}
public static class MockLogFactory extends SLF4J LogFactory {
public static class MockLogFactory extends LogFactoryImpl {
@Override
public Log getInstance ( String name ) throws LogConfigurationException {
if ( AutoConfigurationReportLoggingInitializer . class . getName ( ) . equals ( name ) ) {