View Javadoc
1   /*
2    *    Copyright 2015-2022 the original author or authors.
3    *
4    *    Licensed under the Apache License, Version 2.0 (the "License");
5    *    you may not use this file except in compliance with the License.
6    *    You may obtain a copy of the License at
7    *
8    *       https://www.apache.org/licenses/LICENSE-2.0
9    *
10   *    Unless required by applicable law or agreed to in writing, software
11   *    distributed under the License is distributed on an "AS IS" BASIS,
12   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *    See the License for the specific language governing permissions and
14   *    limitations under the License.
15   */
16  package org.mybatis.spring.boot.test.autoconfigure;
17  
18  import java.util.Collections;
19  import java.util.Set;
20  
21  import org.springframework.boot.context.TypeExcludeFilter;
22  import org.springframework.boot.test.autoconfigure.filter.AnnotationCustomizableTypeExcludeFilter;
23  import org.springframework.context.annotation.ComponentScan;
24  import org.springframework.core.annotation.AnnotatedElementUtils;
25  
26  /**
27   * {@link TypeExcludeFilter} for {@link MybatisTest @MybatisTest}.
28   *
29   * @author wonwoo
30   *
31   * @since 1.2.1
32   */
33  class MybatisTypeExcludeFilter extends AnnotationCustomizableTypeExcludeFilter {
34    private final MybatisTest annotation;
35  
36    MybatisTypeExcludeFilter(Class<?> testClass) {
37      this.annotation = AnnotatedElementUtils.getMergedAnnotation(testClass, MybatisTest.class);
38    }
39  
40    @Override
41    protected boolean hasAnnotation() {
42      return this.annotation != null;
43    }
44  
45    @Override
46    protected ComponentScan.Filter[] getFilters(FilterType type) {
47      switch (type) {
48        case INCLUDE:
49          return this.annotation.includeFilters();
50        case EXCLUDE:
51          return this.annotation.excludeFilters();
52        default:
53          throw new IllegalStateException("Unsupported type " + type);
54      }
55    }
56  
57    @Override
58    protected boolean isUseDefaultFilters() {
59      return this.annotation.useDefaultFilters();
60    }
61  
62    @Override
63    protected Set<Class<?>> getDefaultIncludes() {
64      return Collections.emptySet();
65    }
66  
67    @Override
68    protected Set<Class<?>> getComponentIncludes() {
69      return Collections.emptySet();
70    }
71  
72  }