Skip to content

Commit 11a296b

Browse files
committed
Polish "Fix NPE in BeanDefinitionLoader when XML support is disabled"
See gh-22696
1 parent 2bdeba8 commit 11a296b

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/classpath/ModifiedClassPathExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* @author Christoph Dreis
4343
*/
44-
class ModifiedClassPathExtension implements InvocationInterceptor {
44+
public class ModifiedClassPathExtension implements InvocationInterceptor {
4545

4646
@Override
4747
public void interceptBeforeAllMethod(Invocation<Void> invocation,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot;
18+
19+
import org.junit.jupiter.api.AfterAll;
20+
import org.junit.jupiter.api.BeforeAll;
21+
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.extension.ExtendWith;
23+
24+
import org.springframework.beans.factory.BeanDefinitionStoreException;
25+
import org.springframework.boot.testsupport.classpath.ModifiedClassPathExtension;
26+
import org.springframework.context.support.StaticApplicationContext;
27+
28+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
29+
30+
@ExtendWith(ModifiedClassPathExtension.class)
31+
class IgnoringXmlBeanDefinitionLoaderTests {
32+
33+
@BeforeAll
34+
static void ignoreXml() {
35+
System.setProperty("spring.xml.ignore", "true");
36+
}
37+
38+
@AfterAll
39+
static void enableXml() {
40+
System.clearProperty("spring.xml.ignore");
41+
}
42+
43+
@Test
44+
void whenXmlSupportIsDisabledXmlSourcesAreRejected() {
45+
assertThatExceptionOfType(BeanDefinitionStoreException.class)
46+
.isThrownBy(() -> new BeanDefinitionLoader(new StaticApplicationContext(),
47+
"classpath:org/springframework/boot/sample-beans.xml").load())
48+
.withMessage("Cannot load XML bean definitions when XML support is disabled");
49+
}
50+
51+
}

0 commit comments

Comments
 (0)