This commit is contained in:
Stephane Nicoll
2018-03-11 10:26:41 +01:00
parent 1fa1f2b58a
commit fb7c4a3066
2 changed files with 23 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -51,10 +51,10 @@ public class ImportBeanDefinitionRegistrarTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
context.getBean(MessageSource.class);
assertThat(SampleRegistrar.beanFactory, is((BeanFactory) context.getBeanFactory()));
assertThat(SampleRegistrar.beanFactory, is(context.getBeanFactory()));
assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
assertThat(SampleRegistrar.environment, is((Environment) context.getEnvironment()));
assertThat(SampleRegistrar.environment, is(context.getEnvironment()));
}
@@ -67,12 +67,12 @@ public class ImportBeanDefinitionRegistrarTests {
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import(SampleRegistrar.class)
public static @interface Sample {
public @interface Sample {
}
static class SampleRegistrar implements ImportBeanDefinitionRegistrar, BeanClassLoaderAware, ResourceLoaderAware,
BeanFactoryAware, EnvironmentAware {
private static class SampleRegistrar implements ImportBeanDefinitionRegistrar,
BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware {
static ClassLoader classLoader;
static ResourceLoader resourceLoader;
@@ -100,7 +100,8 @@ public class ImportBeanDefinitionRegistrarTests {
}
@Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
BeanDefinitionRegistry registry) {
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -34,7 +34,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrarTests.SampleRegistrar;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
@@ -79,14 +78,14 @@ public class ImportSelectorTests {
@Test
public void invokeAwareMethodsInImportSelector() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
assertThat(SampleRegistrar.beanFactory, is((BeanFactory) context.getBeanFactory()));
assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
assertThat(SampleRegistrar.environment, is((Environment) context.getEnvironment()));
assertThat(SampleImportSelector.beanFactory, is(context.getBeanFactory()));
assertThat(SampleImportSelector.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(SampleImportSelector.resourceLoader, is(notNullValue()));
assertThat(SampleImportSelector.environment, is(context.getEnvironment()));
}
@Test
public void correctMetaDataOnIndirectImports() throws Exception {
public void correctMetaDataOnIndirectImports() {
new AnnotationConfigApplicationContext(IndirectConfig.class);
Matcher<String> isFromIndirect = equalTo(IndirectImport.class.getName());
assertThat(importFrom.get(ImportSelector1.class), isFromIndirect);
@@ -102,8 +101,8 @@ public class ImportSelectorTests {
}
static class SampleImportSelector implements ImportSelector, BeanClassLoaderAware, ResourceLoaderAware,
BeanFactoryAware, EnvironmentAware {
private static class SampleImportSelector implements ImportSelector,
BeanClassLoaderAware, ResourceLoaderAware, BeanFactoryAware, EnvironmentAware {
static ClassLoader classLoader;
static ResourceLoader resourceLoader;
@@ -112,22 +111,22 @@ public class ImportSelectorTests {
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
SampleRegistrar.classLoader = classLoader;
SampleImportSelector.classLoader = classLoader;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
SampleRegistrar.beanFactory = beanFactory;
SampleImportSelector.beanFactory = beanFactory;
}
@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
SampleRegistrar.resourceLoader = resourceLoader;
SampleImportSelector.resourceLoader = resourceLoader;
}
@Override
public void setEnvironment(Environment environment) {
SampleRegistrar.environment = environment;
SampleImportSelector.environment = environment;
}
@Override
@@ -145,8 +144,9 @@ public class ImportSelectorTests {
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Import({DeferredImportSelector1.class, DeferredImportSelector2.class, ImportSelector1.class, ImportSelector2.class})
public static @interface Sample {
@Import({DeferredImportSelector1.class, DeferredImportSelector2.class,
ImportSelector1.class, ImportSelector2.class})
public @interface Sample {
}