|
4 | 4 | import com.github.javaparser.JavaParser; |
5 | 5 | import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; |
6 | 6 | import com.github.javaparser.ast.expr.AnnotationExpr; |
| 7 | +import com.github.javaparser.ast.nodeTypes.NodeWithName; |
7 | 8 | import de.donnerbart.split.model.Split; |
8 | 9 | import de.donnerbart.split.model.TestCase; |
9 | 10 | import de.donnerbart.split.model.TestSuite; |
|
30 | 31 |
|
31 | 32 | public class TestSplit { |
32 | 33 |
|
33 | | - private static final @NotNull Set<String> SKIP_TEST_ANNOTATIONS = |
34 | | - Set.of("org.junit.jupiter.api.Disabled", "Disabled", "org.junit.Ignore", "Ignore"); |
| 34 | + private static final @NotNull Set<String> SKIP_TEST_IMPORTS = |
| 35 | + Set.of("org.junit.jupiter.api.Disabled", "org.junit.Ignore"); |
| 36 | + private static final @NotNull Set<String> SKIP_TEST_ANNOTATIONS = Set.of("Disabled", "Ignore"); |
35 | 37 |
|
36 | 38 | private static final @NotNull Logger LOG = LoggerFactory.getLogger(TestSplit.class); |
37 | 39 |
|
@@ -195,18 +197,26 @@ public void run() throws Exception { |
195 | 197 | final var className = declaration.getFullyQualifiedName().orElseThrow(); |
196 | 198 | if (declaration.isInterface()) { |
197 | 199 | LOG.info("Skipping test interface {}", className); |
| 200 | + continue; |
198 | 201 | } else if (declaration.isAbstract()) { |
199 | 202 | LOG.info("Skipping abstract test class {}", className); |
200 | | - } else if (declaration.getAnnotations() |
| 203 | + continue; |
| 204 | + } |
| 205 | + final var hasSkipTestImport = compilationUnit.getImports() |
| 206 | + .stream() |
| 207 | + .map(NodeWithName::getNameAsString) |
| 208 | + .anyMatch(SKIP_TEST_IMPORTS::contains); |
| 209 | + final var hasSkipTestAnnotation = declaration.getAnnotations() |
201 | 210 | .stream() |
202 | 211 | .map(AnnotationExpr::getNameAsString) |
203 | | - .anyMatch(SKIP_TEST_ANNOTATIONS::contains)) { |
| 212 | + .anyMatch(SKIP_TEST_ANNOTATIONS::contains); |
| 213 | + if (hasSkipTestImport && hasSkipTestAnnotation) { |
204 | 214 | LOG.info("Skipping disabled test class {}", className); |
205 | | - } else { |
206 | | - classNames.add(className); |
| 215 | + continue; |
207 | 216 | } |
| 217 | + classNames.add(className); |
208 | 218 | } catch (final Exception e) { |
209 | | - LOG.error("Failed to parse test class: {}", testPath, e); |
| 219 | + LOG.error("Failed to parse test class {}", testPath, e); |
210 | 220 | exitCodeConsumer.accept(1); |
211 | 221 | } |
212 | 222 | } |
|
0 commit comments