Polish "Allow MethodReference to support a more flexible signature"
See gh-29005
This commit is contained in:
parent
bbe5e91ebc
commit
0dba729823
|
@ -139,7 +139,7 @@ class ApplicationContextInitializationCodeGenerator implements BeanFactoryInitia
|
|||
}
|
||||
else if (name.equals(ConfigurableEnvironment.class.getName())
|
||||
|| name.equals(Environment.class.getName())) {
|
||||
return CodeBlock.of("$L.getConfigurableEnvironment()", APPLICATION_CONTEXT_VARIABLE);
|
||||
return CodeBlock.of("$L.getEnvironment()", APPLICATION_CONTEXT_VARIABLE);
|
||||
}
|
||||
else if (name.equals(ResourceLoader.class.getName())) {
|
||||
return CodeBlock.of(APPLICATION_CONTEXT_VARIABLE);
|
||||
|
|
|
@ -61,7 +61,10 @@ import org.springframework.context.testfixture.context.generator.annotation.Lazy
|
|||
import org.springframework.context.testfixture.context.generator.annotation.LazyAutowiredMethodComponent;
|
||||
import org.springframework.context.testfixture.context.generator.annotation.LazyConstructorArgumentComponent;
|
||||
import org.springframework.context.testfixture.context.generator.annotation.LazyFactoryMethodArgumentComponent;
|
||||
import org.springframework.context.testfixture.context.generator.annotation.PropertySourceConfiguration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -279,6 +282,19 @@ class ApplicationContextAotGeneratorTests {
|
|||
.withMemberCategory(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(context.getRuntimeHints());
|
||||
}
|
||||
|
||||
@Test
|
||||
void processAheadOfTimeWithPropertySource() {
|
||||
GenericApplicationContext applicationContext = new AnnotationConfigApplicationContext();
|
||||
applicationContext.registerBean(PropertySourceConfiguration.class);
|
||||
testCompiledResult(applicationContext, (initializer, compiled) -> {
|
||||
GenericApplicationContext freshApplicationContext = toFreshApplicationContext(initializer);
|
||||
ConfigurableEnvironment environment = freshApplicationContext.getEnvironment();
|
||||
PropertySource<?> propertySource = environment.getPropertySources().get("testp1");
|
||||
assertThat(propertySource).isNotNull();
|
||||
assertThat(propertySource.getProperty("from.p1")).isEqualTo("p1Value");
|
||||
});
|
||||
}
|
||||
|
||||
private Consumer<List<? extends JdkProxyHint>> doesNotHaveProxyFor(Class<?> target) {
|
||||
return hints -> assertThat(hints).noneMatch(hint -> hint.getProxiedInterfaces().get(0).equals(target));
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ class ApplicationContextInitializationCodeGeneratorTests {
|
|||
|
||||
static Stream<Arguments> methodArguments() {
|
||||
String applicationContext = "applicationContext";
|
||||
String environment = applicationContext + ".getConfigurableEnvironment()";
|
||||
String environment = applicationContext + ".getEnvironment()";
|
||||
return Stream.of(
|
||||
Arguments.of(DefaultListableBeanFactory.class, "beanFactory"),
|
||||
Arguments.of(ConfigurableListableBeanFactory.class, "beanFactory"),
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.testfixture.context.generator.annotation;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@PropertySource(name = "testp1", value = "classpath:org/springframework/context/annotation/p1.properties")
|
||||
public class PropertySourceConfiguration {
|
||||
|
||||
}
|
Loading…
Reference in New Issue