Convert spaces to tabs
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/a0d0325d Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/a0d0325d Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/a0d0325d Branch: refs/heads/3.0-rc1 Commit: a0d0325db046f266abc401abe3e0047f6ce908c3 Parents: 0c32981 Author: Benedikt Ritter <brit...@apache.org> Authored: Mon Feb 6 14:23:03 2017 +0100 Committer: Benedikt Ritter <brit...@apache.org> Committed: Mon Feb 6 14:23:03 2017 +0100 ---------------------------------------------------------------------- .../provider/JUnitPlatformProvider.java | 236 ++++++------ .../surefire/provider/RunListenerAdapter.java | 164 ++++---- .../provider/TestPlanScannerFilter.java | 38 +- .../provider/JUnitPlatformProviderTests.java | 382 +++++++++---------- .../provider/RunListenerAdapterTests.java | 334 ++++++++-------- .../provider/TestPlanScannerFilterTests.java | 228 +++++------ .../src/test/resources/log4j2-test.xml | 26 +- 7 files changed, 704 insertions(+), 704 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java index 676d33f..99f0fd5 100644 --- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java +++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java @@ -48,123 +48,123 @@ import org.junit.platform.launcher.core.LauncherFactory; */ public class JUnitPlatformProvider extends AbstractProvider { - // Parameter names processed to determine which @Tags should be executed. - static final String EXCLUDE_GROUPS = "excludedGroups"; - static final String EXCLUDE_TAGS = "excludeTags"; - static final String INCLUDE_GROUPS = "groups"; - static final String INCLUDE_TAGS = "includeTags"; - - static final String EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED = "The " + INCLUDE_GROUPS + " and " + INCLUDE_TAGS - + " parameters (or the " + EXCLUDE_GROUPS + " and " + EXCLUDE_TAGS + " parameters) are synonyms - " - + "only one of each is allowed (though neither is required)."; - - private final ProviderParameters parameters; - private final Launcher launcher; - final Filter<?>[] includeAndExcludeFilters; - - public JUnitPlatformProvider(ProviderParameters parameters) { - this(parameters, LauncherFactory.create()); - } - - JUnitPlatformProvider(ProviderParameters parameters, Launcher launcher) { - this.parameters = parameters; - this.launcher = launcher; - this.includeAndExcludeFilters = getIncludeAndExcludeFilters(); - Logger.getLogger("org.junit").setLevel(Level.WARNING); - } - - @Override - public Iterable<Class<?>> getSuites() { - return scanClasspath(); - } - - @Override - public RunResult invoke(Object forkTestSet) - throws TestSetFailedException, ReporterException, InvocationTargetException { - if (forkTestSet instanceof TestsToRun) { - return invokeAllTests((TestsToRun) forkTestSet); - } - else if (forkTestSet instanceof Class) { - return invokeAllTests(TestsToRun.fromClass((Class<?>) forkTestSet)); - } - else if (forkTestSet == null) { - return invokeAllTests(scanClasspath()); - } - else { - throw new IllegalArgumentException("Unexpected value of forkTestSet: " + forkTestSet); - } - } - - private TestsToRun scanClasspath() { - TestsToRun scannedClasses = parameters.getScanResult().applyFilter( - new TestPlanScannerFilter(launcher, includeAndExcludeFilters), parameters.getTestClassLoader()); - return parameters.getRunOrderCalculator().orderTestClasses(scannedClasses); - } - - private RunResult invokeAllTests(TestsToRun testsToRun) { - RunResult runResult; - ReporterFactory reporterFactory = parameters.getReporterFactory(); - try { - RunListener runListener = reporterFactory.createReporter(); - launcher.registerTestExecutionListeners(new RunListenerAdapter(runListener)); - - for (Class<?> testClass : testsToRun) { - invokeSingleClass(testClass, runListener); - } - } - finally { - runResult = reporterFactory.close(); - } - return runResult; - } - - private void invokeSingleClass(Class<?> testClass, RunListener runListener) { - SimpleReportEntry classEntry = new SimpleReportEntry(getClass().getName(), testClass.getName()); - runListener.testSetStarting(classEntry); - - LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClass(testClass)).filters( - includeAndExcludeFilters).build(); - launcher.execute(discoveryRequest); - - runListener.testSetCompleted(classEntry); - } - - private Filter<?>[] getIncludeAndExcludeFilters() { - List<Filter<?>> filters = new ArrayList<>(); - - Optional<List<String>> includes = getGroupsOrTags(getPropertiesList(INCLUDE_GROUPS), - getPropertiesList(INCLUDE_TAGS)); - includes.map(TagFilter::includeTags).ifPresent(filters::add); - - Optional<List<String>> excludes = getGroupsOrTags(getPropertiesList(EXCLUDE_GROUPS), - getPropertiesList(EXCLUDE_TAGS)); - excludes.map(TagFilter::excludeTags).ifPresent(filters::add); - - return filters.toArray(new Filter<?>[filters.size()]); - } - - private Optional<List<String>> getPropertiesList(String key) { - List<String> compoundProperties = null; - String property = parameters.getProviderProperties().get(key); - if (property != null) { - compoundProperties = Arrays.asList(property.split("[, ]+")); - } - return Optional.ofNullable(compoundProperties); - } - - private Optional<List<String>> getGroupsOrTags(Optional<List<String>> groups, Optional<List<String>> tags) { - Optional<List<String>> elements = Optional.empty(); - - Preconditions.condition(!groups.isPresent() || !tags.isPresent(), EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED); - - if (groups.isPresent()) { - elements = groups; - } - else if (tags.isPresent()) { - elements = tags; - } - - return elements; - } + // Parameter names processed to determine which @Tags should be executed. + static final String EXCLUDE_GROUPS = "excludedGroups"; + static final String EXCLUDE_TAGS = "excludeTags"; + static final String INCLUDE_GROUPS = "groups"; + static final String INCLUDE_TAGS = "includeTags"; + + static final String EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED = "The " + INCLUDE_GROUPS + " and " + INCLUDE_TAGS + + " parameters (or the " + EXCLUDE_GROUPS + " and " + EXCLUDE_TAGS + " parameters) are synonyms - " + + "only one of each is allowed (though neither is required)."; + + private final ProviderParameters parameters; + private final Launcher launcher; + final Filter<?>[] includeAndExcludeFilters; + + public JUnitPlatformProvider(ProviderParameters parameters) { + this(parameters, LauncherFactory.create()); + } + + JUnitPlatformProvider(ProviderParameters parameters, Launcher launcher) { + this.parameters = parameters; + this.launcher = launcher; + this.includeAndExcludeFilters = getIncludeAndExcludeFilters(); + Logger.getLogger("org.junit").setLevel(Level.WARNING); + } + + @Override + public Iterable<Class<?>> getSuites() { + return scanClasspath(); + } + + @Override + public RunResult invoke(Object forkTestSet) + throws TestSetFailedException, ReporterException, InvocationTargetException { + if (forkTestSet instanceof TestsToRun) { + return invokeAllTests((TestsToRun) forkTestSet); + } + else if (forkTestSet instanceof Class) { + return invokeAllTests(TestsToRun.fromClass((Class<?>) forkTestSet)); + } + else if (forkTestSet == null) { + return invokeAllTests(scanClasspath()); + } + else { + throw new IllegalArgumentException("Unexpected value of forkTestSet: " + forkTestSet); + } + } + + private TestsToRun scanClasspath() { + TestsToRun scannedClasses = parameters.getScanResult().applyFilter( + new TestPlanScannerFilter(launcher, includeAndExcludeFilters), parameters.getTestClassLoader()); + return parameters.getRunOrderCalculator().orderTestClasses(scannedClasses); + } + + private RunResult invokeAllTests(TestsToRun testsToRun) { + RunResult runResult; + ReporterFactory reporterFactory = parameters.getReporterFactory(); + try { + RunListener runListener = reporterFactory.createReporter(); + launcher.registerTestExecutionListeners(new RunListenerAdapter(runListener)); + + for (Class<?> testClass : testsToRun) { + invokeSingleClass(testClass, runListener); + } + } + finally { + runResult = reporterFactory.close(); + } + return runResult; + } + + private void invokeSingleClass(Class<?> testClass, RunListener runListener) { + SimpleReportEntry classEntry = new SimpleReportEntry(getClass().getName(), testClass.getName()); + runListener.testSetStarting(classEntry); + + LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClass(testClass)).filters( + includeAndExcludeFilters).build(); + launcher.execute(discoveryRequest); + + runListener.testSetCompleted(classEntry); + } + + private Filter<?>[] getIncludeAndExcludeFilters() { + List<Filter<?>> filters = new ArrayList<>(); + + Optional<List<String>> includes = getGroupsOrTags(getPropertiesList(INCLUDE_GROUPS), + getPropertiesList(INCLUDE_TAGS)); + includes.map(TagFilter::includeTags).ifPresent(filters::add); + + Optional<List<String>> excludes = getGroupsOrTags(getPropertiesList(EXCLUDE_GROUPS), + getPropertiesList(EXCLUDE_TAGS)); + excludes.map(TagFilter::excludeTags).ifPresent(filters::add); + + return filters.toArray(new Filter<?>[filters.size()]); + } + + private Optional<List<String>> getPropertiesList(String key) { + List<String> compoundProperties = null; + String property = parameters.getProviderProperties().get(key); + if (property != null) { + compoundProperties = Arrays.asList(property.split("[, ]+")); + } + return Optional.ofNullable(compoundProperties); + } + + private Optional<List<String>> getGroupsOrTags(Optional<List<String>> groups, Optional<List<String>> tags) { + Optional<List<String>> elements = Optional.empty(); + + Preconditions.condition(!groups.isPresent() || !tags.isPresent(), EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED); + + if (groups.isPresent()) { + elements = groups; + } + else if (tags.isPresent()) { + elements = tags; + } + + return elements; + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java index 70fb928..ab79ddd 100644 --- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java +++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java @@ -39,86 +39,86 @@ import org.junit.platform.launcher.TestPlan; */ final class RunListenerAdapter implements TestExecutionListener { - private final RunListener runListener; - private Optional<TestPlan> testPlan = Optional.empty(); - - public RunListenerAdapter(RunListener runListener) { - this.runListener = runListener; - } - - @Override - public void testPlanExecutionStarted(TestPlan testPlan) { - this.testPlan = Optional.of(testPlan); - } - - @Override - public void testPlanExecutionFinished(TestPlan testPlan) { - this.testPlan = Optional.empty(); - } - - @Override - public void executionStarted(TestIdentifier testIdentifier) { - if (testIdentifier.isTest()) { - runListener.testStarting(createReportEntry(testIdentifier, Optional.empty())); - } - } - - @Override - public void executionSkipped(TestIdentifier testIdentifier, String reason) { - String source = getClassName(testIdentifier).orElseGet(() -> parentDisplayName(testIdentifier)); - runListener.testSkipped(ignored(source, testIdentifier.getDisplayName(), reason)); - } - - @Override - public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { - if (testExecutionResult.getStatus() == ABORTED) { - runListener.testAssumptionFailure(createReportEntry(testIdentifier, testExecutionResult.getThrowable())); - } - else if (testExecutionResult.getStatus() == FAILED) { - runListener.testFailed(createReportEntry(testIdentifier, testExecutionResult.getThrowable())); - } - else if (testIdentifier.isTest()) { - runListener.testSucceeded(createReportEntry(testIdentifier, Optional.empty())); - } - } - - private SimpleReportEntry createReportEntry(TestIdentifier testIdentifier, Optional<Throwable> throwable) { - Optional<String> className = getClassName(testIdentifier); - if (className.isPresent()) { - StackTraceWriter traceWriter = new PojoStackTraceWriter(className.get(), - getMethodName(testIdentifier).orElse(""), throwable.orElse(null)); - return new SimpleReportEntry(className.get(), testIdentifier.getDisplayName(), traceWriter, null); - } - else { - return new SimpleReportEntry(parentDisplayName(testIdentifier), testIdentifier.getDisplayName(), null); - } - } - - private Optional<String> getClassName(TestIdentifier testIdentifier) { - TestSource testSource = testIdentifier.getSource().orElse(null); - if (testSource instanceof ClassSource) { - return Optional.of(((ClassSource) testSource).getJavaClass().getName()); - } - if (testSource instanceof MethodSource) { - return Optional.of(((MethodSource) testSource).getClassName()); - } - return Optional.empty(); - } - - private Optional<String> getMethodName(TestIdentifier testIdentifier) { - TestSource testSource = testIdentifier.getSource().orElse(null); - if (testSource instanceof MethodSource) { - return Optional.of(((MethodSource) testSource).getMethodName()); - } - return Optional.empty(); - } - - private String parentDisplayName(TestIdentifier testIdentifier) { - // @formatter:off - return testPlan - .flatMap(plan -> plan.getParent(testIdentifier)) - .map(TestIdentifier::getDisplayName) - .orElseGet(testIdentifier::getUniqueId); - // @formatter:on - } + private final RunListener runListener; + private Optional<TestPlan> testPlan = Optional.empty(); + + public RunListenerAdapter(RunListener runListener) { + this.runListener = runListener; + } + + @Override + public void testPlanExecutionStarted(TestPlan testPlan) { + this.testPlan = Optional.of(testPlan); + } + + @Override + public void testPlanExecutionFinished(TestPlan testPlan) { + this.testPlan = Optional.empty(); + } + + @Override + public void executionStarted(TestIdentifier testIdentifier) { + if (testIdentifier.isTest()) { + runListener.testStarting(createReportEntry(testIdentifier, Optional.empty())); + } + } + + @Override + public void executionSkipped(TestIdentifier testIdentifier, String reason) { + String source = getClassName(testIdentifier).orElseGet(() -> parentDisplayName(testIdentifier)); + runListener.testSkipped(ignored(source, testIdentifier.getDisplayName(), reason)); + } + + @Override + public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { + if (testExecutionResult.getStatus() == ABORTED) { + runListener.testAssumptionFailure(createReportEntry(testIdentifier, testExecutionResult.getThrowable())); + } + else if (testExecutionResult.getStatus() == FAILED) { + runListener.testFailed(createReportEntry(testIdentifier, testExecutionResult.getThrowable())); + } + else if (testIdentifier.isTest()) { + runListener.testSucceeded(createReportEntry(testIdentifier, Optional.empty())); + } + } + + private SimpleReportEntry createReportEntry(TestIdentifier testIdentifier, Optional<Throwable> throwable) { + Optional<String> className = getClassName(testIdentifier); + if (className.isPresent()) { + StackTraceWriter traceWriter = new PojoStackTraceWriter(className.get(), + getMethodName(testIdentifier).orElse(""), throwable.orElse(null)); + return new SimpleReportEntry(className.get(), testIdentifier.getDisplayName(), traceWriter, null); + } + else { + return new SimpleReportEntry(parentDisplayName(testIdentifier), testIdentifier.getDisplayName(), null); + } + } + + private Optional<String> getClassName(TestIdentifier testIdentifier) { + TestSource testSource = testIdentifier.getSource().orElse(null); + if (testSource instanceof ClassSource) { + return Optional.of(((ClassSource) testSource).getJavaClass().getName()); + } + if (testSource instanceof MethodSource) { + return Optional.of(((MethodSource) testSource).getClassName()); + } + return Optional.empty(); + } + + private Optional<String> getMethodName(TestIdentifier testIdentifier) { + TestSource testSource = testIdentifier.getSource().orElse(null); + if (testSource instanceof MethodSource) { + return Optional.of(((MethodSource) testSource).getMethodName()); + } + return Optional.empty(); + } + + private String parentDisplayName(TestIdentifier testIdentifier) { + // @formatter:off + return testPlan + .flatMap(plan -> plan.getParent(testIdentifier)) + .map(TestIdentifier::getDisplayName) + .orElseGet(testIdentifier::getUniqueId); + // @formatter:on + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java index fd1796d..29d2f52 100644 --- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java +++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java @@ -33,24 +33,24 @@ import org.junit.platform.launcher.TestPlan; */ final class TestPlanScannerFilter implements ScannerFilter { - private static final Predicate<TestIdentifier> hasTests = testIdentifier -> testIdentifier.isTest() - || testIdentifier.isContainer(); - - private final Launcher launcher; - private final Filter<?>[] includeAndExcludeFilters; - - public TestPlanScannerFilter(Launcher launcher, Filter<?>[] includeAndExcludeFilters) { - this.launcher = launcher; - this.includeAndExcludeFilters = includeAndExcludeFilters; - } - - @Override - @SuppressWarnings("rawtypes") - public boolean accept(Class testClass) { - LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClass(testClass)).filters( - includeAndExcludeFilters).build(); - TestPlan testPlan = launcher.discover(discoveryRequest); - return testPlan.countTestIdentifiers(hasTests) > 0; - } + private static final Predicate<TestIdentifier> hasTests = testIdentifier -> testIdentifier.isTest() + || testIdentifier.isContainer(); + + private final Launcher launcher; + private final Filter<?>[] includeAndExcludeFilters; + + public TestPlanScannerFilter(Launcher launcher, Filter<?>[] includeAndExcludeFilters) { + this.launcher = launcher; + this.includeAndExcludeFilters = includeAndExcludeFilters; + } + + @Override + @SuppressWarnings("rawtypes") + public boolean accept(Class testClass) { + LauncherDiscoveryRequest discoveryRequest = request().selectors(selectClass(testClass)).filters( + includeAndExcludeFilters).build(); + TestPlan testPlan = launcher.discover(discoveryRequest); + return testPlan.countTestIdentifiers(hasTests) > 0; + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java index 798e471..ef9201a 100644 --- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java +++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java @@ -53,234 +53,234 @@ import org.junit.platform.launcher.listeners.TestExecutionSummary; */ class JUnitPlatformProviderTests { - @Test - void getSuitesReturnsScannedClasses() throws Exception { - ProviderParameters providerParameters = providerParametersMock(TestClass1.class, TestClass2.class); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); + @Test + void getSuitesReturnsScannedClasses() throws Exception { + ProviderParameters providerParameters = providerParametersMock(TestClass1.class, TestClass2.class); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); - assertThat(provider.getSuites()).containsOnly(TestClass1.class, TestClass2.class); - } - - @Test - void invokeThrowsForWrongForkTestSet() throws Exception { - ProviderParameters providerParameters = providerParametersMock(Integer.class); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); + assertThat(provider.getSuites()).containsOnly(TestClass1.class, TestClass2.class); + } + + @Test + void invokeThrowsForWrongForkTestSet() throws Exception { + ProviderParameters providerParameters = providerParametersMock(Integer.class); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); - assertThrows(IllegalArgumentException.class, () -> provider.invoke("wrong forkTestSet")); - } + assertThrows(IllegalArgumentException.class, () -> provider.invoke("wrong forkTestSet")); + } - @Test - void allGivenTestsToRunAreInvoked() throws Exception { - Launcher launcher = LauncherFactory.create(); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher); + @Test + void allGivenTestsToRunAreInvoked() throws Exception { + Launcher launcher = LauncherFactory.create(); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher); - TestPlanSummaryListener executionListener = new TestPlanSummaryListener(); - launcher.registerTestExecutionListeners(executionListener); + TestPlanSummaryListener executionListener = new TestPlanSummaryListener(); + launcher.registerTestExecutionListeners(executionListener); - TestsToRun testsToRun = newTestsToRun(TestClass1.class, TestClass2.class); - provider.invoke(testsToRun); + TestsToRun testsToRun = newTestsToRun(TestClass1.class, TestClass2.class); + provider.invoke(testsToRun); - assertThat(executionListener.summaries).hasSize(2); - TestClass1.verifyExecutionSummary(executionListener.summaries.get(0)); - TestClass2.verifyExecutionSummary(executionListener.summaries.get(1)); - } + assertThat(executionListener.summaries).hasSize(2); + TestClass1.verifyExecutionSummary(executionListener.summaries.get(0)); + TestClass2.verifyExecutionSummary(executionListener.summaries.get(1)); + } - @Test - void singleTestClassIsInvoked() throws Exception { - Launcher launcher = LauncherFactory.create(); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher); + @Test + void singleTestClassIsInvoked() throws Exception { + Launcher launcher = LauncherFactory.create(); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher); - TestPlanSummaryListener executionListener = new TestPlanSummaryListener(); - launcher.registerTestExecutionListeners(executionListener); + TestPlanSummaryListener executionListener = new TestPlanSummaryListener(); + launcher.registerTestExecutionListeners(executionListener); - provider.invoke(TestClass1.class); + provider.invoke(TestClass1.class); - assertThat(executionListener.summaries).hasSize(1); - TestClass1.verifyExecutionSummary(executionListener.summaries.get(0)); - } + assertThat(executionListener.summaries).hasSize(1); + TestClass1.verifyExecutionSummary(executionListener.summaries.get(0)); + } - @Test - void allDiscoveredTestsAreInvokedForNullArgument() throws Exception { - ProviderParameters providerParameters = providerParametersMock(TestClass1.class, TestClass2.class); - Launcher launcher = LauncherFactory.create(); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher); + @Test + void allDiscoveredTestsAreInvokedForNullArgument() throws Exception { + ProviderParameters providerParameters = providerParametersMock(TestClass1.class, TestClass2.class); + Launcher launcher = LauncherFactory.create(); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher); - TestPlanSummaryListener executionListener = new TestPlanSummaryListener(); - launcher.registerTestExecutionListeners(executionListener); + TestPlanSummaryListener executionListener = new TestPlanSummaryListener(); + launcher.registerTestExecutionListeners(executionListener); - provider.invoke(null); + provider.invoke(null); - assertThat(executionListener.summaries).hasSize(2); - TestClass1.verifyExecutionSummary(executionListener.summaries.get(0)); - TestClass2.verifyExecutionSummary(executionListener.summaries.get(1)); - } + assertThat(executionListener.summaries).hasSize(2); + TestClass1.verifyExecutionSummary(executionListener.summaries.get(0)); + TestClass2.verifyExecutionSummary(executionListener.summaries.get(1)); + } - @Test - void bothGroupsAndIncludeTagsThrowsException() { - Map<String, String> properties = new HashMap<>(); - properties.put(JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo"); - properties.put(JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo"); - verifyPreconditionViolationException(properties); - } + @Test + void bothGroupsAndIncludeTagsThrowsException() { + Map<String, String> properties = new HashMap<>(); + properties.put(JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo"); + properties.put(JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo"); + verifyPreconditionViolationException(properties); + } - @Test - void bothExcludedGroupsAndExcludeTagsThrowsException() { - Map<String, String> properties = new HashMap<>(); - properties.put(JUnitPlatformProvider.EXCLUDE_GROUPS, "groupOne, groupTwo"); - properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagOne, tagTwo"); - verifyPreconditionViolationException(properties); - } + @Test + void bothExcludedGroupsAndExcludeTagsThrowsException() { + Map<String, String> properties = new HashMap<>(); + properties.put(JUnitPlatformProvider.EXCLUDE_GROUPS, "groupOne, groupTwo"); + properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagOne, tagTwo"); + verifyPreconditionViolationException(properties); + } - @Test - void onlyGroupsIsDeclared() throws Exception { - Map<String, String> properties = new HashMap<>(); - properties.put(JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo"); + @Test + void onlyGroupsIsDeclared() throws Exception { + Map<String, String> properties = new HashMap<>(); + properties.put(JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo"); - ProviderParameters providerParameters = providerParametersMock(TestClass1.class); - when(providerParameters.getProviderProperties()).thenReturn(properties); + ProviderParameters providerParameters = providerParametersMock(TestClass1.class); + when(providerParameters.getProviderProperties()).thenReturn(properties); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); - assertEquals(1, provider.includeAndExcludeFilters.length); - } + assertEquals(1, provider.includeAndExcludeFilters.length); + } - @Test - void onlyExcludeTagsIsDeclared() throws Exception { - Map<String, String> properties = new HashMap<>(); - properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagOne, tagTwo"); + @Test + void onlyExcludeTagsIsDeclared() throws Exception { + Map<String, String> properties = new HashMap<>(); + properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagOne, tagTwo"); - ProviderParameters providerParameters = providerParametersMock(TestClass1.class); - when(providerParameters.getProviderProperties()).thenReturn(properties); + ProviderParameters providerParameters = providerParametersMock(TestClass1.class); + when(providerParameters.getProviderProperties()).thenReturn(properties); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); - assertEquals(1, provider.includeAndExcludeFilters.length); - } + assertEquals(1, provider.includeAndExcludeFilters.length); + } - @Test - void bothIncludeAndExcludeAreAllowed() throws Exception { - Map<String, String> properties = new HashMap<>(); - properties.put(JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo"); - properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagThree, tagFour"); + @Test + void bothIncludeAndExcludeAreAllowed() throws Exception { + Map<String, String> properties = new HashMap<>(); + properties.put(JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo"); + properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagThree, tagFour"); - ProviderParameters providerParameters = providerParametersMock(TestClass1.class); - when(providerParameters.getProviderProperties()).thenReturn(properties); + ProviderParameters providerParameters = providerParametersMock(TestClass1.class); + when(providerParameters.getProviderProperties()).thenReturn(properties); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); - assertEquals(2, provider.includeAndExcludeFilters.length); - } + assertEquals(2, provider.includeAndExcludeFilters.length); + } - @Test - void noFiltersAreCreatedIfNoPropertiesAreDeclared() throws Exception { - ProviderParameters providerParameters = providerParametersMock(TestClass1.class); + @Test + void noFiltersAreCreatedIfNoPropertiesAreDeclared() throws Exception { + ProviderParameters providerParameters = providerParametersMock(TestClass1.class); - JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); + JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters); - assertEquals(0, provider.includeAndExcludeFilters.length); - } + assertEquals(0, provider.includeAndExcludeFilters.length); + } - private void verifyPreconditionViolationException(Map<String, String> properties) { - ProviderParameters providerParameters = providerParametersMock(TestClass1.class); - when(providerParameters.getProviderProperties()).thenReturn(properties); - - Throwable throwable = assertThrows(PreconditionViolationException.class, () -> { - new JUnitPlatformProvider(providerParameters); - }); - - assertEquals(JUnitPlatformProvider.EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED, throwable.getMessage()); - } - - private static ProviderParameters providerParametersMock(Class<?>... testClasses) { - TestsToRun testsToRun = newTestsToRun(testClasses); - - ScanResult scanResult = mock(ScanResult.class); - when(scanResult.applyFilter(any(), any())).thenReturn(testsToRun); - - RunOrderCalculator runOrderCalculator = mock(RunOrderCalculator.class); - when(runOrderCalculator.orderTestClasses(any())).thenReturn(testsToRun); - - ReporterFactory reporterFactory = mock(ReporterFactory.class); - RunListener runListener = mock(RunListener.class); - when(reporterFactory.createReporter()).thenReturn(runListener); - - ProviderParameters providerParameters = mock(ProviderParameters.class); - when(providerParameters.getScanResult()).thenReturn(scanResult); - when(providerParameters.getRunOrderCalculator()).thenReturn(runOrderCalculator); - when(providerParameters.getReporterFactory()).thenReturn(reporterFactory); - - return providerParameters; - } - - private static TestsToRun newTestsToRun(Class<?>... testClasses) { - List<Class<?>> classesList = Arrays.asList(testClasses); - return new TestsToRun(new LinkedHashSet<>(classesList)); - } - - private class TestPlanSummaryListener extends SummaryGeneratingListener { - - final List<TestExecutionSummary> summaries = new ArrayList<>(); + private void verifyPreconditionViolationException(Map<String, String> properties) { + ProviderParameters providerParameters = providerParametersMock(TestClass1.class); + when(providerParameters.getProviderProperties()).thenReturn(properties); + + Throwable throwable = assertThrows(PreconditionViolationException.class, () -> { + new JUnitPlatformProvider(providerParameters); + }); + + assertEquals(JUnitPlatformProvider.EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED, throwable.getMessage()); + } + + private static ProviderParameters providerParametersMock(Class<?>... testClasses) { + TestsToRun testsToRun = newTestsToRun(testClasses); + + ScanResult scanResult = mock(ScanResult.class); + when(scanResult.applyFilter(any(), any())).thenReturn(testsToRun); + + RunOrderCalculator runOrderCalculator = mock(RunOrderCalculator.class); + when(runOrderCalculator.orderTestClasses(any())).thenReturn(testsToRun); + + ReporterFactory reporterFactory = mock(ReporterFactory.class); + RunListener runListener = mock(RunListener.class); + when(reporterFactory.createReporter()).thenReturn(runListener); + + ProviderParameters providerParameters = mock(ProviderParameters.class); + when(providerParameters.getScanResult()).thenReturn(scanResult); + when(providerParameters.getRunOrderCalculator()).thenReturn(runOrderCalculator); + when(providerParameters.getReporterFactory()).thenReturn(reporterFactory); + + return providerParameters; + } + + private static TestsToRun newTestsToRun(Class<?>... testClasses) { + List<Class<?>> classesList = Arrays.asList(testClasses); + return new TestsToRun(new LinkedHashSet<>(classesList)); + } + + private class TestPlanSummaryListener extends SummaryGeneratingListener { + + final List<TestExecutionSummary> summaries = new ArrayList<>(); - @Override - public void testPlanExecutionFinished(TestPlan testPlan) { - super.testPlanExecutionFinished(testPlan); - summaries.add(getSummary()); - } - } + @Override + public void testPlanExecutionFinished(TestPlan testPlan) { + super.testPlanExecutionFinished(testPlan); + summaries.add(getSummary()); + } + } - private static class TestClass1 { + private static class TestClass1 { - @Test - void test1() { - } + @Test + void test1() { + } - @Test - void test2() { - } + @Test + void test2() { + } - @Disabled - @Test - void test3() { - } + @Disabled + @Test + void test3() { + } - @Test - void test4() { - throw new RuntimeException(); - } + @Test + void test4() { + throw new RuntimeException(); + } - static void verifyExecutionSummary(TestExecutionSummary summary) { - assertEquals(4, summary.getTestsFoundCount()); - assertEquals(3, summary.getTestsStartedCount()); - assertEquals(2, summary.getTestsSucceededCount()); - assertEquals(1, summary.getTestsSkippedCount()); - assertEquals(0, summary.getTestsAbortedCount()); - assertEquals(1, summary.getTestsFailedCount()); - } - } - - private static class TestClass2 { - - @Test - void test1() { - } - - @Test - void test2() { - throw new RuntimeException(); - } - - @Test - void test3() { - assumeTrue(false); - } - - static void verifyExecutionSummary(TestExecutionSummary summary) { - assertEquals(3, summary.getTestsFoundCount()); - assertEquals(3, summary.getTestsStartedCount()); - assertEquals(1, summary.getTestsSucceededCount()); - assertEquals(0, summary.getTestsSkippedCount()); - assertEquals(1, summary.getTestsAbortedCount()); - assertEquals(1, summary.getTestsFailedCount()); - } - } + static void verifyExecutionSummary(TestExecutionSummary summary) { + assertEquals(4, summary.getTestsFoundCount()); + assertEquals(3, summary.getTestsStartedCount()); + assertEquals(2, summary.getTestsSucceededCount()); + assertEquals(1, summary.getTestsSkippedCount()); + assertEquals(0, summary.getTestsAbortedCount()); + assertEquals(1, summary.getTestsFailedCount()); + } + } + + private static class TestClass2 { + + @Test + void test1() { + } + + @Test + void test2() { + throw new RuntimeException(); + } + + @Test + void test3() { + assumeTrue(false); + } + + static void verifyExecutionSummary(TestExecutionSummary summary) { + assertEquals(3, summary.getTestsFoundCount()); + assertEquals(3, summary.getTestsStartedCount()); + assertEquals(1, summary.getTestsSucceededCount()); + assertEquals(0, summary.getTestsSkippedCount()); + assertEquals(1, summary.getTestsAbortedCount()); + assertEquals(1, summary.getTestsFailedCount()); + } + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java index c343ff6..3b8f34c 100644 --- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java +++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java @@ -49,171 +49,171 @@ import org.mockito.ArgumentCaptor; */ class RunListenerAdapterTests { - private RunListener listener; - private RunListenerAdapter adapter; - - @BeforeEach - public void setUp() { - listener = mock(RunListener.class); - adapter = new RunListenerAdapter(listener); - } - - @Test - void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exception { - ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); - - adapter.executionStarted(newMethodIdentifier()); - verify(listener).testStarting(entryCaptor.capture()); - - ReportEntry entry = entryCaptor.getValue(); - assertEquals(MY_TEST_METHOD_NAME + "()", entry.getName()); - assertEquals(MyTestClass.class.getName(), entry.getSourceName()); - assertNotNull(entry.getStackTraceWriter()); - } - - @Test - void notNotifiedWhenClassExecutionStarted() throws Exception { - adapter.executionStarted(newClassIdentifier()); - verify(listener, never()).testStarting(any()); - } - - @Test - void notNotifiedWhenEngineExecutionStarted() throws Exception { - adapter.executionStarted(newEngineIdentifier()); - verify(listener, never()).testStarting(any()); - } - - @Test - void notifiedWhenMethodExecutionSkipped() throws Exception { - adapter.executionSkipped(newMethodIdentifier(), "test"); - verify(listener).testSkipped(any()); - } - - @Test - void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception { - ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); - - adapter.executionSkipped(newClassIdentifier(), "test"); - verify(listener).testSkipped(entryCaptor.capture()); - - ReportEntry entry = entryCaptor.getValue(); - assertTrue(MyTestClass.class.getTypeName().contains(entry.getName())); - assertEquals(MyTestClass.class.getName(), entry.getSourceName()); - } - - @Test - void notifiedWhenEngineExecutionSkipped() throws Exception { - adapter.executionSkipped(newEngineIdentifier(), "test"); - verify(listener).testSkipped(any()); - } - - @Test - void notifiedWhenMethodExecutionAborted() throws Exception { - adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.aborted(null)); - verify(listener).testAssumptionFailure(any()); - } - - @Test - void notifiedWhenClassExecutionAborted() throws Exception { - adapter.executionFinished(newClassIdentifier(), TestExecutionResult.aborted(null)); - verify(listener).testAssumptionFailure(any()); - } - - @Test - void notifiedWhenMethodExecutionFailed() throws Exception { - adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.failed(new RuntimeException())); - verify(listener).testFailed(any()); - } - - @Test - void notifiedWithCorrectNamesWhenClassExecutionFailed() throws Exception { - ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); - - adapter.executionFinished(newClassIdentifier(), TestExecutionResult.failed(new RuntimeException())); - verify(listener).testFailed(entryCaptor.capture()); - - ReportEntry entry = entryCaptor.getValue(); - assertEquals(MyTestClass.class.getName(), entry.getSourceName()); - assertNotNull(entry.getStackTraceWriter()); - } - - @Test - void notifiedWhenMethodExecutionSucceeded() throws Exception { - adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.successful()); - verify(listener).testSucceeded(any()); - } - - @Test - void notNotifiedWhenClassExecutionSucceeded() throws Exception { - adapter.executionFinished(newClassIdentifier(), TestExecutionResult.successful()); - verify(listener, never()).testSucceeded(any()); - } - - @Test - void notifiedWithParentDisplayNameWhenTestClassUnknown() throws Exception { - // Set up a test plan - TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan"))); - adapter.testPlanExecutionStarted(plan); - - // Use the test plan to set up child with parent. - final String parentDisplay = "I am your father"; - TestIdentifier child = newSourcelessIdentifierWithParent(plan, parentDisplay); - adapter.executionStarted(child); - - // Check that the adapter has informed Surefire that the test has been invoked, - // with the parent name as source (since the test case itself had no source). - ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); - verify(listener).testStarting(entryCaptor.capture()); - assertEquals(parentDisplay, entryCaptor.getValue().getSourceName()); - } - - private static TestIdentifier newMethodIdentifier() throws Exception { - TestDescriptor testDescriptor = new MethodTestDescriptor(newId(), MyTestClass.class, - MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME)); - return TestIdentifier.from(testDescriptor); - } - - private static TestIdentifier newClassIdentifier() { - TestDescriptor testDescriptor = new ClassTestDescriptor(newId(), MyTestClass.class); - return TestIdentifier.from(testDescriptor); - } - - private static TestIdentifier newSourcelessIdentifierWithParent(TestPlan testPlan, String parentDisplay) { - // A parent test identifier with a name. - TestDescriptor parent = mock(TestDescriptor.class); - when(parent.getUniqueId()).thenReturn(newId()); - when(parent.getDisplayName()).thenReturn(parentDisplay); - TestIdentifier parentId = TestIdentifier.from(parent); - - // The (child) test case that is to be executed as part of a test plan. - TestDescriptor child = mock(TestDescriptor.class); - when(child.getUniqueId()).thenReturn(newId()); - when(child.isTest()).thenReturn(true); - - // Ensure the child source is null yet that there is a parent -- the special case to be tested. - when(child.getSource()).thenReturn(Optional.empty()); - when(child.getParent()).thenReturn(Optional.of(parent)); - TestIdentifier childId = TestIdentifier.from(child); - - testPlan.add(childId); - testPlan.add(parentId); - - return childId; - } - - private static TestIdentifier newEngineIdentifier() { - TestDescriptor testDescriptor = new EngineDescriptor(newId(), "engine"); - return TestIdentifier.from(testDescriptor); - } - - private static UniqueId newId() { - return UniqueId.forEngine("engine"); - } - - private static final String MY_TEST_METHOD_NAME = "myTestMethod"; - private static class MyTestClass { - @Test - void myTestMethod() { - } - } + private RunListener listener; + private RunListenerAdapter adapter; + + @BeforeEach + public void setUp() { + listener = mock(RunListener.class); + adapter = new RunListenerAdapter(listener); + } + + @Test + void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exception { + ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); + + adapter.executionStarted(newMethodIdentifier()); + verify(listener).testStarting(entryCaptor.capture()); + + ReportEntry entry = entryCaptor.getValue(); + assertEquals(MY_TEST_METHOD_NAME + "()", entry.getName()); + assertEquals(MyTestClass.class.getName(), entry.getSourceName()); + assertNotNull(entry.getStackTraceWriter()); + } + + @Test + void notNotifiedWhenClassExecutionStarted() throws Exception { + adapter.executionStarted(newClassIdentifier()); + verify(listener, never()).testStarting(any()); + } + + @Test + void notNotifiedWhenEngineExecutionStarted() throws Exception { + adapter.executionStarted(newEngineIdentifier()); + verify(listener, never()).testStarting(any()); + } + + @Test + void notifiedWhenMethodExecutionSkipped() throws Exception { + adapter.executionSkipped(newMethodIdentifier(), "test"); + verify(listener).testSkipped(any()); + } + + @Test + void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception { + ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); + + adapter.executionSkipped(newClassIdentifier(), "test"); + verify(listener).testSkipped(entryCaptor.capture()); + + ReportEntry entry = entryCaptor.getValue(); + assertTrue(MyTestClass.class.getTypeName().contains(entry.getName())); + assertEquals(MyTestClass.class.getName(), entry.getSourceName()); + } + + @Test + void notifiedWhenEngineExecutionSkipped() throws Exception { + adapter.executionSkipped(newEngineIdentifier(), "test"); + verify(listener).testSkipped(any()); + } + + @Test + void notifiedWhenMethodExecutionAborted() throws Exception { + adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.aborted(null)); + verify(listener).testAssumptionFailure(any()); + } + + @Test + void notifiedWhenClassExecutionAborted() throws Exception { + adapter.executionFinished(newClassIdentifier(), TestExecutionResult.aborted(null)); + verify(listener).testAssumptionFailure(any()); + } + + @Test + void notifiedWhenMethodExecutionFailed() throws Exception { + adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.failed(new RuntimeException())); + verify(listener).testFailed(any()); + } + + @Test + void notifiedWithCorrectNamesWhenClassExecutionFailed() throws Exception { + ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); + + adapter.executionFinished(newClassIdentifier(), TestExecutionResult.failed(new RuntimeException())); + verify(listener).testFailed(entryCaptor.capture()); + + ReportEntry entry = entryCaptor.getValue(); + assertEquals(MyTestClass.class.getName(), entry.getSourceName()); + assertNotNull(entry.getStackTraceWriter()); + } + + @Test + void notifiedWhenMethodExecutionSucceeded() throws Exception { + adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.successful()); + verify(listener).testSucceeded(any()); + } + + @Test + void notNotifiedWhenClassExecutionSucceeded() throws Exception { + adapter.executionFinished(newClassIdentifier(), TestExecutionResult.successful()); + verify(listener, never()).testSucceeded(any()); + } + + @Test + void notifiedWithParentDisplayNameWhenTestClassUnknown() throws Exception { + // Set up a test plan + TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan"))); + adapter.testPlanExecutionStarted(plan); + + // Use the test plan to set up child with parent. + final String parentDisplay = "I am your father"; + TestIdentifier child = newSourcelessIdentifierWithParent(plan, parentDisplay); + adapter.executionStarted(child); + + // Check that the adapter has informed Surefire that the test has been invoked, + // with the parent name as source (since the test case itself had no source). + ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class); + verify(listener).testStarting(entryCaptor.capture()); + assertEquals(parentDisplay, entryCaptor.getValue().getSourceName()); + } + + private static TestIdentifier newMethodIdentifier() throws Exception { + TestDescriptor testDescriptor = new MethodTestDescriptor(newId(), MyTestClass.class, + MyTestClass.class.getDeclaredMethod(MY_TEST_METHOD_NAME)); + return TestIdentifier.from(testDescriptor); + } + + private static TestIdentifier newClassIdentifier() { + TestDescriptor testDescriptor = new ClassTestDescriptor(newId(), MyTestClass.class); + return TestIdentifier.from(testDescriptor); + } + + private static TestIdentifier newSourcelessIdentifierWithParent(TestPlan testPlan, String parentDisplay) { + // A parent test identifier with a name. + TestDescriptor parent = mock(TestDescriptor.class); + when(parent.getUniqueId()).thenReturn(newId()); + when(parent.getDisplayName()).thenReturn(parentDisplay); + TestIdentifier parentId = TestIdentifier.from(parent); + + // The (child) test case that is to be executed as part of a test plan. + TestDescriptor child = mock(TestDescriptor.class); + when(child.getUniqueId()).thenReturn(newId()); + when(child.isTest()).thenReturn(true); + + // Ensure the child source is null yet that there is a parent -- the special case to be tested. + when(child.getSource()).thenReturn(Optional.empty()); + when(child.getParent()).thenReturn(Optional.of(parent)); + TestIdentifier childId = TestIdentifier.from(child); + + testPlan.add(childId); + testPlan.add(parentId); + + return childId; + } + + private static TestIdentifier newEngineIdentifier() { + TestDescriptor testDescriptor = new EngineDescriptor(newId(), "engine"); + return TestIdentifier.from(testDescriptor); + } + + private static UniqueId newId() { + return UniqueId.forEngine("engine"); + } + + private static final String MY_TEST_METHOD_NAME = "myTestMethod"; + private static class MyTestClass { + @Test + void myTestMethod() { + } + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java index bd48d66..37e6b7f 100644 --- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java +++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java @@ -36,122 +36,122 @@ import org.junit.platform.launcher.core.LauncherFactory; */ public class TestPlanScannerFilterTests { - @Test - void emptyClassAccepted() { - assertTrue(newFilter().accept(EmptyClass.class), "accepts empty class because it is a container"); - } - - @Test - void classWithNoTestMethodsIsAccepted() { - assertTrue(newFilter().accept(ClassWithMethods.class), - "accepts class with no @Test methods because it is a container"); - } + @Test + void emptyClassAccepted() { + assertTrue(newFilter().accept(EmptyClass.class), "accepts empty class because it is a container"); + } + + @Test + void classWithNoTestMethodsIsAccepted() { + assertTrue(newFilter().accept(ClassWithMethods.class), + "accepts class with no @Test methods because it is a container"); + } - @Test - void classWithTestMethodsIsAccepted() { - assertTrue(newFilter().accept(ClassWithTestMethods.class)); - } - - @Test - void classWithNestedTestClassIsAccepted() { - assertTrue(newFilter().accept(ClassWithNestedTestClass.class)); - } - - @Test - void classWithDeeplyNestedTestClassIsAccepted() { - assertTrue(newFilter().accept(ClassWithDeeplyNestedTestClass.class)); - } - - @Test - void classWithTestFactoryIsAccepted() { - assertTrue(newFilter().accept(ClassWithTestFactory.class)); - } - - @Test - void classWithNestedTestFactoryIsAccepted() { - assertTrue(newFilter().accept(ClassWithNestedTestFactory.class)); - } - - private TestPlanScannerFilter newFilter() { - return new TestPlanScannerFilter(LauncherFactory.create(), new Filter<?>[0]); - } - - private static class EmptyClass { - } - - @SuppressWarnings("unused") - private static class ClassWithMethods { - - void method1() { - } - - void method2() { - } - } - - private static class ClassWithTestMethods { - - @Test - void test1() { - } - - @Test - public void test2() { - } - } - - private static class ClassWithNestedTestClass { - - @SuppressWarnings("unused") - void method() { - } - - @Nested - class TestClass { - - @Test - void test1() { - } - } - } - - private static class ClassWithDeeplyNestedTestClass { - - @Nested - class Level1 { - - @Nested - class Level2 { - - @Nested - class TestClass { - - @Test - void test1() { - } - } - } - } - } - - private static class ClassWithTestFactory { - - @TestFactory - Stream<DynamicTest> tests() { - return Stream.empty(); - } - } - - private static class ClassWithNestedTestFactory { + @Test + void classWithTestMethodsIsAccepted() { + assertTrue(newFilter().accept(ClassWithTestMethods.class)); + } + + @Test + void classWithNestedTestClassIsAccepted() { + assertTrue(newFilter().accept(ClassWithNestedTestClass.class)); + } + + @Test + void classWithDeeplyNestedTestClassIsAccepted() { + assertTrue(newFilter().accept(ClassWithDeeplyNestedTestClass.class)); + } + + @Test + void classWithTestFactoryIsAccepted() { + assertTrue(newFilter().accept(ClassWithTestFactory.class)); + } + + @Test + void classWithNestedTestFactoryIsAccepted() { + assertTrue(newFilter().accept(ClassWithNestedTestFactory.class)); + } + + private TestPlanScannerFilter newFilter() { + return new TestPlanScannerFilter(LauncherFactory.create(), new Filter<?>[0]); + } + + private static class EmptyClass { + } + + @SuppressWarnings("unused") + private static class ClassWithMethods { + + void method1() { + } + + void method2() { + } + } + + private static class ClassWithTestMethods { + + @Test + void test1() { + } + + @Test + public void test2() { + } + } + + private static class ClassWithNestedTestClass { + + @SuppressWarnings("unused") + void method() { + } + + @Nested + class TestClass { + + @Test + void test1() { + } + } + } + + private static class ClassWithDeeplyNestedTestClass { + + @Nested + class Level1 { + + @Nested + class Level2 { + + @Nested + class TestClass { + + @Test + void test1() { + } + } + } + } + } + + private static class ClassWithTestFactory { + + @TestFactory + Stream<DynamicTest> tests() { + return Stream.empty(); + } + } + + private static class ClassWithNestedTestFactory { - @Nested - class TestClass { + @Nested + class TestClass { - @TestFactory - List<DynamicTest> tests() { - return emptyList(); - } - } - } + @TestFactory + List<DynamicTest> tests() { + return emptyList(); + } + } + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a0d0325d/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml b/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml index 27875d9..c1b215e 100644 --- a/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml +++ b/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml @@ -1,15 +1,15 @@ <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> - <Appenders> - <Console name="Console" target="SYSTEM_OUT"> - <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> - </Console> - </Appenders> - <Loggers> - <Logger name="org.junit" level="warn" /> - <Logger name="org.junit.platform.surefire" level="error" /> - <Root level="error"> - <AppenderRef ref="Console" /> - </Root> - </Loggers> -</Configuration> \ No newline at end of file + <Appenders> + <Console name="Console" target="SYSTEM_OUT"> + <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> + </Console> + </Appenders> + <Loggers> + <Logger name="org.junit" level="warn" /> + <Logger name="org.junit.platform.surefire" level="error" /> + <Root level="error"> + <AppenderRef ref="Console" /> + </Root> + </Loggers> +</Configuration>