15
15
import ch .qos .logback .classic .ClassicTestConstants ;
16
16
import ch .qos .logback .classic .Logger ;
17
17
import ch .qos .logback .classic .LoggerContext ;
18
- import ch .qos .logback .classic .joran .JoranConfigurator ;
19
18
import ch .qos .logback .classic .spi .ILoggingEvent ;
20
19
import ch .qos .logback .core .Appender ;
21
20
import ch .qos .logback .core .ConsoleAppender ;
@@ -161,7 +160,9 @@ public void shouldConfigureFromXmlFile() throws MalformedURLException, JoranExce
161
160
162
161
URL configurationFileUrl = Loader .getResource ("BOO_logback-test.xml" ,
163
162
Thread .currentThread ().getContextClassLoader ());
164
- configureByResource (configurationFileUrl );
163
+ DefaultJoranConfigurator joranConfigurator = new DefaultJoranConfigurator ();
164
+ joranConfigurator .setContext (loggerContext );
165
+ joranConfigurator .configureByResource (configurationFileUrl );
165
166
166
167
assertNotNull (loggerContext .getObject (CoreConstants .SAFE_JORAN_CONFIGURATION ));
167
168
}
@@ -178,25 +179,13 @@ public void shouldConfigureFromXmlFile() throws MalformedURLException, JoranExce
178
179
// assertNotNull(loggerContext.getObject(CoreConstants.CONFIGURATION_WATCH_LIST));
179
180
// }
180
181
181
- private void configureByResource (URL url ) throws JoranException {
182
- if (url == null ) {
183
- throw new IllegalArgumentException ("URL argument cannot be null" );
184
- }
185
- final String urlString = url .toString ();
186
- if (urlString .endsWith ("xml" )) {
187
- JoranConfigurator configurator = new JoranConfigurator ();
188
- configurator .setContext (loggerContext );
189
- configurator .doConfigure (url );
190
- } else {
191
- throw new LogbackException ("Unexpected filename extension of file [" + url + "]. Should be .xml" );
192
- }
193
- }
194
-
195
182
@ Test
196
183
public void shouldThrowExceptionIfUnexpectedConfigurationFileExtension () throws JoranException {
197
184
URL configurationFileUrl = Loader .getResource ("README.txt" , Thread .currentThread ().getContextClassLoader ());
198
185
try {
199
- this .configureByResource (configurationFileUrl );
186
+ DefaultJoranConfigurator joranConfigurator = new DefaultJoranConfigurator ();
187
+ joranConfigurator .setContext (loggerContext );
188
+ joranConfigurator .configureByResource (configurationFileUrl );
200
189
fail ("Should throw LogbackException" );
201
190
} catch (LogbackException expectedException ) {
202
191
// pass
0 commit comments