|
| 1 | +/* |
| 2 | + * Copyright 2015-2025 the original author or authors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials are |
| 5 | + * made available under the terms of the Eclipse Public License v2.0 which |
| 6 | + * accompanies this distribution and is available at |
| 7 | + * |
| 8 | + * https://www.eclipse.org/legal/epl-v20.html |
| 9 | + */ |
| 10 | + |
| 11 | +package org.junit.platform.launcher.core; |
| 12 | + |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; |
| 14 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; |
| 15 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClasspathResource; |
| 16 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectDirectory; |
| 17 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectFile; |
| 18 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod; |
| 19 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage; |
| 20 | +import static org.junit.platform.engine.discovery.DiscoverySelectors.selectUri; |
| 21 | +import static org.mockito.Mockito.mock; |
| 22 | + |
| 23 | +import java.io.File; |
| 24 | +import java.net.URI; |
| 25 | +import java.util.stream.Stream; |
| 26 | + |
| 27 | +import org.junit.jupiter.params.ParameterizedTest; |
| 28 | +import org.junit.jupiter.params.provider.MethodSource; |
| 29 | +import org.junit.platform.engine.DiscoveryIssue; |
| 30 | +import org.junit.platform.engine.DiscoveryIssue.Severity; |
| 31 | +import org.junit.platform.engine.DiscoverySelector; |
| 32 | +import org.junit.platform.engine.SelectorResolutionResult; |
| 33 | +import org.junit.platform.engine.TestSource; |
| 34 | +import org.junit.platform.engine.UniqueId; |
| 35 | +import org.junit.platform.engine.discovery.FilePosition; |
| 36 | +import org.junit.platform.engine.support.descriptor.ClassSource; |
| 37 | +import org.junit.platform.engine.support.descriptor.ClasspathResourceSource; |
| 38 | +import org.junit.platform.engine.support.descriptor.DirectorySource; |
| 39 | +import org.junit.platform.engine.support.descriptor.FileSource; |
| 40 | +import org.junit.platform.engine.support.descriptor.PackageSource; |
| 41 | +import org.junit.platform.engine.support.descriptor.UriSource; |
| 42 | + |
| 43 | +class DiscoveryIssueCollectorTests { |
| 44 | + |
| 45 | + @ParameterizedTest(name = "{0}") |
| 46 | + @MethodSource("pairs") |
| 47 | + void reportsFailedResolutionResultAsDiscoveryIssue(Pair pair) { |
| 48 | + var collector = new DiscoveryIssueCollector(mock()); |
| 49 | + var failure = SelectorResolutionResult.failed(new RuntimeException("boom")); |
| 50 | + collector.selectorProcessed(UniqueId.forEngine("dummy"), pair.selector, failure); |
| 51 | + |
| 52 | + var expectedIssue = DiscoveryIssue.builder(Severity.ERROR, pair.selector + " resolution failed") // |
| 53 | + .cause(failure.getThrowable()) // |
| 54 | + .source(pair.source).build(); |
| 55 | + assertThat(collector.toNotifier().getAllIssues()).containsExactly(expectedIssue); |
| 56 | + } |
| 57 | + |
| 58 | + public static Stream<Pair> pairs() { |
| 59 | + return Stream.of( // |
| 60 | + new Pair(selectClass("SomeClass"), ClassSource.from("SomeClass")), // |
| 61 | + new Pair(selectMethod("SomeClass#someMethod(int,int)"), |
| 62 | + org.junit.platform.engine.support.descriptor.MethodSource.from("SomeClass", "someMethod", "int,int")), // |
| 63 | + new Pair(selectClasspathResource("someResource"), ClasspathResourceSource.from("someResource")), // |
| 64 | + new Pair(selectClasspathResource("someResource", FilePosition.from(42)), |
| 65 | + ClasspathResourceSource.from("someResource", |
| 66 | + org.junit.platform.engine.support.descriptor.FilePosition.from(42))), // |
| 67 | + new Pair(selectClasspathResource("someResource", FilePosition.from(42, 23)), |
| 68 | + ClasspathResourceSource.from("someResource", |
| 69 | + org.junit.platform.engine.support.descriptor.FilePosition.from(42, 23))), // |
| 70 | + new Pair(selectPackage("some.package"), PackageSource.from("some.package")), // |
| 71 | + new Pair(selectFile("someFile"), FileSource.from(new File("someFile"))), // |
| 72 | + new Pair(selectFile("someFile", FilePosition.from(42)), |
| 73 | + FileSource.from(new File("someFile"), |
| 74 | + org.junit.platform.engine.support.descriptor.FilePosition.from(42))), // |
| 75 | + new Pair(selectFile("someFile", FilePosition.from(42, 23)), |
| 76 | + FileSource.from(new File("someFile"), |
| 77 | + org.junit.platform.engine.support.descriptor.FilePosition.from(42, 23))), // |
| 78 | + new Pair(selectDirectory("someDir"), DirectorySource.from(new File("someDir"))), // |
| 79 | + new Pair(selectUri("some:uri"), UriSource.from(URI.create("some:uri"))) // |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + record Pair(DiscoverySelector selector, TestSource source) { |
| 84 | + } |
| 85 | +} |
0 commit comments