Search in sources :

Example 6 with ContextCustomizer

use of org.springframework.test.context.ContextCustomizer in project spring-boot by spring-projects.

the class TypeExcludeFiltersContextCustomizerFactoryTests method hashCodeAndEquals.

@Test
public void hashCodeAndEquals() throws Exception {
    ContextCustomizer customizer1 = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
    ContextCustomizer customizer2 = this.factory.createContextCustomizer(WithSameExcludeFilters.class, null);
    ContextCustomizer customizer3 = this.factory.createContextCustomizer(WithDifferentExcludeFilters.class, null);
    assertThat(customizer1.hashCode()).isEqualTo(customizer2.hashCode());
    assertThat(customizer1).isEqualTo(customizer1).isEqualTo(customizer2).isNotEqualTo(customizer3);
}
Also used : ContextCustomizer(org.springframework.test.context.ContextCustomizer) Test(org.junit.Test)

Example 7 with ContextCustomizer

use of org.springframework.test.context.ContextCustomizer in project spring-boot by spring-projects.

the class TypeExcludeFiltersContextCustomizerFactoryTests method getContextCustomizerShouldAddExcludeFilters.

@Test
public void getContextCustomizerShouldAddExcludeFilters() throws Exception {
    ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
    customizer.customizeContext(this.context, this.mergedContextConfiguration);
    this.context.refresh();
    TypeExcludeFilter filter = this.context.getBean(TypeExcludeFilter.class);
    MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
    MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(NoAnnotation.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isFalse();
    metadataReader = metadataReaderFactory.getMetadataReader(SimpleExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
    metadataReader = metadataReaderFactory.getMetadataReader(TestClassAwareExclude.class.getName());
    assertThat(filter.match(metadataReader, metadataReaderFactory)).isTrue();
}
Also used : MetadataReaderFactory(org.springframework.core.type.classreading.MetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) SimpleMetadataReaderFactory(org.springframework.core.type.classreading.SimpleMetadataReaderFactory) ContextCustomizer(org.springframework.test.context.ContextCustomizer) TypeExcludeFilter(org.springframework.boot.context.TypeExcludeFilter) MetadataReader(org.springframework.core.type.classreading.MetadataReader) Test(org.junit.Test)

Example 8 with ContextCustomizer

use of org.springframework.test.context.ContextCustomizer in project spring-boot by spring-projects.

the class TypeExcludeFiltersContextCustomizerFactoryTests method getContextCustomizerWhenHasNoAnnotationShouldReturnNull.

@Test
public void getContextCustomizerWhenHasNoAnnotationShouldReturnNull() throws Exception {
    ContextCustomizer customizer = this.factory.createContextCustomizer(NoAnnotation.class, null);
    assertThat(customizer).isNull();
}
Also used : ContextCustomizer(org.springframework.test.context.ContextCustomizer) Test(org.junit.Test)

Example 9 with ContextCustomizer

use of org.springframework.test.context.ContextCustomizer in project spring-boot by spring-projects.

the class TypeExcludeFiltersContextCustomizerFactoryTests method getContextCustomizerWhenHasAnnotationShouldReturnCustomizer.

@Test
public void getContextCustomizerWhenHasAnnotationShouldReturnCustomizer() throws Exception {
    ContextCustomizer customizer = this.factory.createContextCustomizer(WithExcludeFilters.class, null);
    assertThat(customizer).isNotNull();
}
Also used : ContextCustomizer(org.springframework.test.context.ContextCustomizer) Test(org.junit.Test)

Example 10 with ContextCustomizer

use of org.springframework.test.context.ContextCustomizer in project spring-boot by spring-projects.

the class ImportsContextCustomizerFactoryTests method contextCustomizerImportsBeans.

@Test
public void contextCustomizerImportsBeans() throws Exception {
    ContextCustomizer customizer = this.factory.createContextCustomizer(TestWithImport.class, null);
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    customizer.customizeContext(context, mock(MergedContextConfiguration.class));
    context.refresh();
    assertThat(context.getBean(ImportedBean.class)).isNotNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MergedContextConfiguration(org.springframework.test.context.MergedContextConfiguration) ContextCustomizer(org.springframework.test.context.ContextCustomizer) Test(org.junit.Test)

Aggregations

ContextCustomizer (org.springframework.test.context.ContextCustomizer)25 Test (org.junit.Test)22 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)3 ArrayList (java.util.ArrayList)2 MergedContextConfiguration (org.springframework.test.context.MergedContextConfiguration)2 LinkedHashSet (java.util.LinkedHashSet)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 TypeExcludeFilter (org.springframework.boot.context.TypeExcludeFilter)1 ServletContextApplicationContextInitializer (org.springframework.boot.web.servlet.support.ServletContextApplicationContextInitializer)1 ApplicationContextInitializer (org.springframework.context.ApplicationContextInitializer)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)1 MetadataReader (org.springframework.core.type.classreading.MetadataReader)1 MetadataReaderFactory (org.springframework.core.type.classreading.MetadataReaderFactory)1 SimpleMetadataReaderFactory (org.springframework.core.type.classreading.SimpleMetadataReaderFactory)1 ContextConfigurationAttributes (org.springframework.test.context.ContextConfigurationAttributes)1 ContextCustomizerFactory (org.springframework.test.context.ContextCustomizerFactory)1 ContextLoader (org.springframework.test.context.ContextLoader)1 SmartContextLoader (org.springframework.test.context.SmartContextLoader)1