Skip to content

Commit

Permalink
Avoid use of bean overriding in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Mar 26, 2024
1 parent 9f8a26f commit 866af12
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,6 @@
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.mock.web.MockFilterChain;
Expand Down Expand Up @@ -241,14 +240,14 @@ private void assertRestartInvoked(boolean value) {
private AnnotationConfigServletWebApplicationContext loadContext(String... properties) {
AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
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);
context.refresh();
return context;
}

@Configuration(proxyBeanMethods = false)
@Import({ SecurityAutoConfiguration.class, RemoteDevToolsAutoConfiguration.class })
static class Config {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -117,7 +117,7 @@ void aotContributedInitializerBindsValueObjectWithSpecificConstructor() {
@Test
@CompileWithForkedClassLoader
void aotContributedInitializerBindsJavaBean() {
compile(createContext(JavaBeanSampleBeanConfiguration.class), (freshContext) -> {
compile(createContext(), (freshContext) -> {
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(freshContext, "test.name=Hello");
freshContext.refresh();
JavaBeanSampleBean bean = freshContext.getBean(JavaBeanSampleBean.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void loadWhenBindingWithoutAnnotationValueShouldBind() {
@Test
void loadWhenBindingWithDefaultsInXmlShouldBind() {
removeSystemProperties();
load(new Class<?>[] { BasicConfiguration.class, DefaultsInXmlConfiguration.class });
load(new Class<?>[] { DefaultsInXmlConfiguration.class });
BasicProperties bean = this.context.getBean(BasicProperties.class);
assertThat(bean.name).isEqualTo("bar");
}
Expand Down Expand Up @@ -1354,6 +1354,7 @@ static class WithoutAnnotationValueConfiguration {
}

@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
@ImportResource("org/springframework/boot/context/properties/testProperties.xml")
static class DefaultsInXmlConfiguration {

Expand Down

0 comments on commit 866af12

Please sign in to comment.