mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Avoid use of bean overriding in tests
See gh-40111
This commit is contained in:
parent
af0353ddd3
commit
49c97bf6ca
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -36,7 +36,6 @@ import org.springframework.boot.test.util.TestPropertyValues;
|
|||||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.Import;
|
|
||||||
import org.springframework.http.server.ServerHttpRequest;
|
import org.springframework.http.server.ServerHttpRequest;
|
||||||
import org.springframework.http.server.ServerHttpResponse;
|
import org.springframework.http.server.ServerHttpResponse;
|
||||||
import org.springframework.mock.web.MockFilterChain;
|
import org.springframework.mock.web.MockFilterChain;
|
||||||
@ -241,14 +240,14 @@ class RemoteDevToolsAutoConfigurationTests {
|
|||||||
private AnnotationConfigServletWebApplicationContext loadContext(String... properties) {
|
private AnnotationConfigServletWebApplicationContext loadContext(String... properties) {
|
||||||
AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
|
AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
|
||||||
context.setServletContext(new MockServletContext());
|
context.setServletContext(new MockServletContext());
|
||||||
context.register(Config.class, PropertyPlaceholderAutoConfiguration.class);
|
context.register(Config.class, SecurityAutoConfiguration.class, RemoteDevToolsAutoConfiguration.class,
|
||||||
|
PropertyPlaceholderAutoConfiguration.class);
|
||||||
TestPropertyValues.of(properties).applyTo(context);
|
TestPropertyValues.of(properties).applyTo(context);
|
||||||
context.refresh();
|
context.refresh();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
@Import({ SecurityAutoConfiguration.class, RemoteDevToolsAutoConfiguration.class })
|
|
||||||
static class Config {
|
static class Config {
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2012-2023 the original author or authors.
|
* Copyright 2012-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -117,7 +117,7 @@ class ConfigurationPropertiesBeanRegistrationAotProcessorTests {
|
|||||||
@Test
|
@Test
|
||||||
@CompileWithForkedClassLoader
|
@CompileWithForkedClassLoader
|
||||||
void aotContributedInitializerBindsJavaBean() {
|
void aotContributedInitializerBindsJavaBean() {
|
||||||
compile(createContext(JavaBeanSampleBeanConfiguration.class), (freshContext) -> {
|
compile(createContext(), (freshContext) -> {
|
||||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "test.name=Hello");
|
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "test.name=Hello");
|
||||||
freshContext.refresh();
|
freshContext.refresh();
|
||||||
JavaBeanSampleBean bean = freshContext.getBean(JavaBeanSampleBean.class);
|
JavaBeanSampleBean bean = freshContext.getBean(JavaBeanSampleBean.class);
|
||||||
|
@ -261,7 +261,7 @@ class ConfigurationPropertiesTests {
|
|||||||
@Test
|
@Test
|
||||||
void loadWhenBindingWithDefaultsInXmlShouldBind() {
|
void loadWhenBindingWithDefaultsInXmlShouldBind() {
|
||||||
removeSystemProperties();
|
removeSystemProperties();
|
||||||
load(new Class<?>[] { BasicConfiguration.class, DefaultsInXmlConfiguration.class });
|
load(new Class<?>[] { DefaultsInXmlConfiguration.class });
|
||||||
BasicProperties bean = this.context.getBean(BasicProperties.class);
|
BasicProperties bean = this.context.getBean(BasicProperties.class);
|
||||||
assertThat(bean.name).isEqualTo("bar");
|
assertThat(bean.name).isEqualTo("bar");
|
||||||
}
|
}
|
||||||
@ -1354,6 +1354,7 @@ class ConfigurationPropertiesTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false)
|
@Configuration(proxyBeanMethods = false)
|
||||||
|
@EnableConfigurationProperties
|
||||||
@ImportResource("org/springframework/boot/context/properties/testProperties.xml")
|
@ImportResource("org/springframework/boot/context/properties/testProperties.xml")
|
||||||
static class DefaultsInXmlConfiguration {
|
static class DefaultsInXmlConfiguration {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user