Java 类org.springframework.boot.context.TypeExcludeFilter 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TypeExcludeFiltersContextCustomizer.java   
private TypeExcludeFilter createDelegatingTypeExcludeFilter() {
    final Set<TypeExcludeFilter> filters = new LinkedHashSet<TypeExcludeFilter>(
            this.filterClasses.size());
    for (Class<? extends TypeExcludeFilter> filterClass : this.filterClasses) {
        filters.add(createTypeExcludeFilter(filterClass));
    }
    return new TypeExcludeFilter() {

        @Override
        public boolean match(MetadataReader metadataReader,
                MetadataReaderFactory metadataReaderFactory) throws IOException {
            for (TypeExcludeFilter filter : filters) {
                if (filter.match(metadataReader, metadataReaderFactory)) {
                    return true;
                }
            }
            return false;
        }

    };
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TypeExcludeFiltersContextCustomizerFactoryTests.java   
@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();
}
项目:spring-boot-concourse    文件:TypeExcludeFiltersContextCustomizer.java   
private TypeExcludeFilter createDelegatingTypeExcludeFilter() {
    final Set<TypeExcludeFilter> filters = new LinkedHashSet<TypeExcludeFilter>(
            this.filterClasses.size());
    for (Class<? extends TypeExcludeFilter> filterClass : this.filterClasses) {
        filters.add(createTypeExcludeFilter(filterClass));
    }
    return new TypeExcludeFilter() {

        @Override
        public boolean match(MetadataReader metadataReader,
                MetadataReaderFactory metadataReaderFactory) throws IOException {
            for (TypeExcludeFilter filter : filters) {
                if (filter.match(metadataReader, metadataReaderFactory)) {
                    return true;
                }
            }
            return false;
        }

    };
}
项目:spring-boot-concourse    文件:TypeExcludeFiltersContextCustomizerFactoryTests.java   
@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();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TypeExcludeFiltersContextCustomizer.java   
private TypeExcludeFilter createTypeExcludeFilter(Class<?> type) {
    try {
        Constructor<?> constructor = getTypeExcludeFilterConstructor(type);
        ReflectionUtils.makeAccessible(constructor);
        if (constructor.getParameterTypes().length == 1) {
            return (TypeExcludeFilter) constructor.newInstance(this.testClass);
        }
        return (TypeExcludeFilter) constructor.newInstance();
    }
    catch (Exception ex) {
        throw new IllegalStateException("Unable to create filter for " + type, ex);
    }
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TypeExcludeFiltersContextCustomizerFactory.java   
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
        List<ContextConfigurationAttributes> configurationAttributes) {
    TypeExcludeFilters annotation = AnnotatedElementUtils
            .findMergedAnnotation(testClass, TypeExcludeFilters.class);
    if (annotation != null) {
        Set<Class<? extends TypeExcludeFilter>> filterClasses = new LinkedHashSet<Class<? extends TypeExcludeFilter>>(
                Arrays.asList(annotation.value()));
        return new TypeExcludeFiltersContextCustomizer(testClass, filterClasses);
    }
    return null;
}
项目:spring-boot-concourse    文件:TypeExcludeFiltersContextCustomizer.java   
private TypeExcludeFilter createTypeExcludeFilter(Class<?> type) {
    try {
        Constructor<?> constructor = getTypeExcludeFilterConstructor(type);
        ReflectionUtils.makeAccessible(constructor);
        if (constructor.getParameterTypes().length == 1) {
            return (TypeExcludeFilter) constructor.newInstance(this.testClass);
        }
        return (TypeExcludeFilter) constructor.newInstance();
    }
    catch (Exception ex) {
        throw new IllegalStateException("Unable to create filter for " + type, ex);
    }
}
项目:spring-boot-concourse    文件:TypeExcludeFiltersContextCustomizerFactory.java   
@Override
public ContextCustomizer createContextCustomizer(Class<?> testClass,
        List<ContextConfigurationAttributes> configurationAttributes) {
    TypeExcludeFilters annotation = AnnotatedElementUtils
            .findMergedAnnotation(testClass, TypeExcludeFilters.class);
    if (annotation != null) {
        Set<Class<? extends TypeExcludeFilter>> filterClasses = new LinkedHashSet<Class<? extends TypeExcludeFilter>>(
                Arrays.asList(annotation.value()));
        return new TypeExcludeFiltersContextCustomizer(testClass, filterClasses);
    }
    return null;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:TypeExcludeFiltersContextCustomizer.java   
TypeExcludeFiltersContextCustomizer(Class<?> testClass,
        Set<Class<? extends TypeExcludeFilter>> filterClasses) {
    this.testClass = testClass;
    this.filterClasses = filterClasses;
}
项目:spring-boot-concourse    文件:TypeExcludeFiltersContextCustomizer.java   
TypeExcludeFiltersContextCustomizer(Class<?> testClass,
        Set<Class<? extends TypeExcludeFilter>> filterClasses) {
    this.testClass = testClass;
    this.filterClasses = filterClasses;
}