You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2017/02/13 23:36:55 UTC
[01/16] maven-surefire git commit: SUREFIRE-1330: Import code from
https://issues.apache.org/jira/browse/SUREFIRE-1330 unchanged as provided
Repository: maven-surefire
Updated Branches:
refs/heads/3.0-rc1 b1f190427 -> c9a1f973e
SUREFIRE-1330: Import code from https://issues.apache.org/jira/browse/SUREFIRE-1330 unchanged as provided
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/73e09a8b
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/73e09a8b
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/73e09a8b
Branch: refs/heads/3.0-rc1
Commit: 73e09a8b2b245e76e072c1809e7fa50be02e95b6
Parents: b1f1904
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 14:02:48 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 14:02:48 2017 +0100
----------------------------------------------------------------------
surefire-providers/surefire-junit5/LICENSE.md | 194 +++++++++++++
.../provider/JUnitPlatformProvider.java | 170 +++++++++++
.../surefire/provider/RunListenerAdapter.java | 124 ++++++++
.../provider/TestPlanScannerFilter.java | 56 ++++
.../surefire/provider/package-info.java | 5 +
....maven.surefire.providerapi.SurefireProvider | 1 +
.../provider/JUnitPlatformProviderTests.java | 286 +++++++++++++++++++
.../provider/RunListenerAdapterTests.java | 219 ++++++++++++++
.../provider/SurefireProviderTestSuite.java | 45 +++
.../provider/TestPlanScannerFilterTests.java | 157 ++++++++++
.../src/test/resources/log4j2-test.xml | 15 +
11 files changed, 1272 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/surefire-providers/surefire-junit5/LICENSE.md
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/LICENSE.md b/surefire-providers/surefire-junit5/LICENSE.md
new file mode 100644
index 0000000..b62a9b5
--- /dev/null
+++ b/surefire-providers/surefire-junit5/LICENSE.md
@@ -0,0 +1,194 @@
+Apache License
+==============
+
+_Version 2.0, January 2004_
+_<<http://www.apache.org/licenses/>>_
+
+### Terms and Conditions for use, reproduction, and distribution
+
+#### 1. Definitions
+
+\u201cLicense\u201d shall mean the terms and conditions for use, reproduction, and
+distribution as defined by Sections 1 through 9 of this document.
+
+\u201cLicensor\u201d shall mean the copyright owner or entity authorized by the copyright
+owner that is granting the License.
+
+\u201cLegal Entity\u201d shall mean the union of the acting entity and all other entities
+that control, are controlled by, or are under common control with that entity.
+For the purposes of this definition, \u201ccontrol\u201d means **(i)** the power, direct or
+indirect, to cause the direction or management of such entity, whether by
+contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
+outstanding shares, or **(iii)** beneficial ownership of such entity.
+
+\u201cYou\u201d (or \u201cYour\u201d) shall mean an individual or Legal Entity exercising
+permissions granted by this License.
+
+\u201cSource\u201d form shall mean the preferred form for making modifications, including
+but not limited to software source code, documentation source, and configuration
+files.
+
+\u201cObject\u201d form shall mean any form resulting from mechanical transformation or
+translation of a Source form, including but not limited to compiled object code,
+generated documentation, and conversions to other media types.
+
+\u201cWork\u201d shall mean the work of authorship, whether in Source or Object form, made
+available under the License, as indicated by a copyright notice that is included
+in or attached to the work (an example is provided in the Appendix below).
+
+\u201cDerivative Works\u201d shall mean any work, whether in Source or Object form, that
+is based on (or derived from) the Work and for which the editorial revisions,
+annotations, elaborations, or other modifications represent, as a whole, an
+original work of authorship. For the purposes of this License, Derivative Works
+shall not include works that remain separable from, or merely link (or bind by
+name) to the interfaces of, the Work and Derivative Works thereof.
+
+\u201cContribution\u201d shall mean any work of authorship, including the original version
+of the Work and any modifications or additions to that Work or Derivative Works
+thereof, that is intentionally submitted to Licensor for inclusion in the Work
+by the copyright owner or by an individual or Legal Entity authorized to submit
+on behalf of the copyright owner. For the purposes of this definition,
+\u201csubmitted\u201d means any form of electronic, verbal, or written communication sent
+to the Licensor or its representatives, including but not limited to
+communication on electronic mailing lists, source code control systems, and
+issue tracking systems that are managed by, or on behalf of, the Licensor for
+the purpose of discussing and improving the Work, but excluding communication
+that is conspicuously marked or otherwise designated in writing by the copyright
+owner as \u201cNot a Contribution.\u201d
+
+\u201cContributor\u201d shall mean Licensor and any individual or Legal Entity on behalf
+of whom a Contribution has been received by Licensor and subsequently
+incorporated within the Work.
+
+#### 2. Grant of Copyright License
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the Work and such
+Derivative Works in Source or Object form.
+
+#### 3. Grant of Patent License
+
+Subject to the terms and conditions of this License, each Contributor hereby
+grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
+irrevocable (except as stated in this section) patent license to make, have
+made, use, offer to sell, sell, import, and otherwise transfer the Work, where
+such license applies only to those patent claims licensable by such Contributor
+that are necessarily infringed by their Contribution(s) alone or by combination
+of their Contribution(s) with the Work to which such Contribution(s) was
+submitted. If You institute patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Work or a
+Contribution incorporated within the Work constitutes direct or contributory
+patent infringement, then any patent licenses granted to You under this License
+for that Work shall terminate as of the date such litigation is filed.
+
+#### 4. Redistribution
+
+You may reproduce and distribute copies of the Work or Derivative Works thereof
+in any medium, with or without modifications, and in Source or Object form,
+provided that You meet the following conditions:
+
+* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
+this License; and
+* **(b)** You must cause any modified files to carry prominent notices stating that You
+changed the files; and
+* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
+all copyright, patent, trademark, and attribution notices from the Source form
+of the Work, excluding those notices that do not pertain to any part of the
+Derivative Works; and
+* **(d)** If the Work includes a \u201cNOTICE\u201d text file as part of its distribution, then any
+Derivative Works that You distribute must include a readable copy of the
+attribution notices contained within such NOTICE file, excluding those notices
+that do not pertain to any part of the Derivative Works, in at least one of the
+following places: within a NOTICE text file distributed as part of the
+Derivative Works; within the Source form or documentation, if provided along
+with the Derivative Works; or, within a display generated by the Derivative
+Works, if and wherever such third-party notices normally appear. The contents of
+the NOTICE file are for informational purposes only and do not modify the
+License. You may add Your own attribution notices within Derivative Works that
+You distribute, alongside or as an addendum to the NOTICE text from the Work,
+provided that such additional attribution notices cannot be construed as
+modifying the License.
+
+You may add Your own copyright statement to Your modifications and may provide
+additional or different license terms and conditions for use, reproduction, or
+distribution of Your modifications, or for any such Derivative Works as a whole,
+provided Your use, reproduction, and distribution of the Work otherwise complies
+with the conditions stated in this License.
+
+#### 5. Submission of Contributions
+
+Unless You explicitly state otherwise, any Contribution intentionally submitted
+for inclusion in the Work by You to the Licensor shall be under the terms and
+conditions of this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify the terms of
+any separate license agreement you may have executed with Licensor regarding
+such Contributions.
+
+#### 6. Trademarks
+
+This License does not grant permission to use the trade names, trademarks,
+service marks, or product names of the Licensor, except as required for
+reasonable and customary use in describing the origin of the Work and
+reproducing the content of the NOTICE file.
+
+#### 7. Disclaimer of Warranty
+
+Unless required by applicable law or agreed to in writing, Licensor provides the
+Work (and each Contributor provides its Contributions) on an \u201cAS IS\u201d BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
+including, without limitation, any warranties or conditions of TITLE,
+NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
+solely responsible for determining the appropriateness of using or
+redistributing the Work and assume any risks associated with Your exercise of
+permissions under this License.
+
+#### 8. Limitation of Liability
+
+In no event and under no legal theory, whether in tort (including negligence),
+contract, or otherwise, unless required by applicable law (such as deliberate
+and grossly negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special, incidental,
+or consequential damages of any character arising as a result of this License or
+out of the use or inability to use the Work (including but not limited to
+damages for loss of goodwill, work stoppage, computer failure or malfunction, or
+any and all other commercial damages or losses), even if such Contributor has
+been advised of the possibility of such damages.
+
+#### 9. Accepting Warranty or Additional Liability
+
+While redistributing the Work or Derivative Works thereof, You may choose to
+offer, and charge a fee for, acceptance of support, warranty, indemnity, or
+other liability obligations and/or rights consistent with this License. However,
+in accepting such obligations, You may act only on Your own behalf and on Your
+sole responsibility, not on behalf of any other Contributor, and only if You
+agree to indemnify, defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason of your
+accepting any such warranty or additional liability.
+
+_END OF TERMS AND CONDITIONS_
+
+### APPENDIX: How to apply the Apache License to your work
+
+To apply the Apache License to your work, attach the following boilerplate
+notice, with the fields enclosed by brackets `[]` replaced with your own
+identifying information. (Don't include the brackets!) The text should be
+enclosed in the appropriate comment syntax for the file format. We also
+recommend that a file or class name and description of purpose be included on
+the same \u201cprinted page\u201d as the copyright notice for easier identification within
+third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..676d33f
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.maven.surefire.providerapi.AbstractProvider;
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.platform.commons.util.Preconditions;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.TagFilter;
+import org.junit.platform.launcher.core.LauncherFactory;
+
+/**
+ * @since 1.0
+ */
+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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..70fb928
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
+import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
+import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
+
+import java.util.Optional;
+
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.TestSource;
+import org.junit.platform.engine.support.descriptor.ClassSource;
+import org.junit.platform.engine.support.descriptor.MethodSource;
+import org.junit.platform.launcher.TestExecutionListener;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+
+/**
+ * @since 1.0
+ */
+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
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..fd1796d
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
+import java.util.function.Predicate;
+
+import org.apache.maven.surefire.util.ScannerFilter;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+
+/**
+ * @since 1.0
+ */
+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;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
new file mode 100644
index 0000000..29b0c3d
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Maven Surefire provider for the JUnit Platform.
+ */
+
+package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider b/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
new file mode 100644
index 0000000..bb76525
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
@@ -0,0 +1 @@
+org.junit.platform.surefire.provider.JUnitPlatformProvider
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..798e471
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.util.RunOrderCalculator;
+import org.apache.maven.surefire.util.ScanResult;
+import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.platform.commons.util.PreconditionViolationException;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.TestPlan;
+import org.junit.platform.launcher.core.LauncherFactory;
+import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
+import org.junit.platform.launcher.listeners.TestExecutionSummary;
+
+/**
+ * Unit tests for {@link JUnitPlatformProvider}.
+ *
+ * @since 1.0
+ */
+class JUnitPlatformProviderTests {
+
+ @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);
+
+ assertThrows(IllegalArgumentException.class, () -> provider.invoke("wrong forkTestSet"));
+ }
+
+ @Test
+ void allGivenTestsToRunAreInvoked() throws Exception {
+ Launcher launcher = LauncherFactory.create();
+ JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners(executionListener);
+
+ 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));
+ }
+
+ @Test
+ void singleTestClassIsInvoked() throws Exception {
+ Launcher launcher = LauncherFactory.create();
+ JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners(executionListener);
+
+ provider.invoke(TestClass1.class);
+
+ 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);
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners(executionListener);
+
+ provider.invoke(null);
+
+ 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 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");
+
+ ProviderParameters providerParameters = providerParametersMock(TestClass1.class);
+ when(providerParameters.getProviderProperties()).thenReturn(properties);
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters);
+
+ assertEquals(1, provider.includeAndExcludeFilters.length);
+ }
+
+ @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);
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters);
+
+ 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");
+
+ ProviderParameters providerParameters = providerParametersMock(TestClass1.class);
+ when(providerParameters.getProviderProperties()).thenReturn(properties);
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters);
+
+ assertEquals(2, provider.includeAndExcludeFilters.length);
+ }
+
+ @Test
+ void noFiltersAreCreatedIfNoPropertiesAreDeclared() throws Exception {
+ ProviderParameters providerParameters = providerParametersMock(TestClass1.class);
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters);
+
+ 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<>();
+
+ @Override
+ public void testPlanExecutionFinished(TestPlan testPlan) {
+ super.testPlanExecutionFinished(testPlan);
+ summaries.add(getSummary());
+ }
+ }
+
+ private static class TestClass1 {
+
+ @Test
+ void test1() {
+ }
+
+ @Test
+ void test2() {
+ }
+
+ @Disabled
+ @Test
+ void test3() {
+ }
+
+ @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());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..c343ff6
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java
@@ -0,0 +1,219 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Collections;
+import java.util.Optional;
+
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.RunListener;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
+import org.junit.jupiter.engine.descriptor.MethodTestDescriptor;
+import org.junit.platform.engine.TestDescriptor;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.UniqueId;
+import org.junit.platform.engine.support.descriptor.EngineDescriptor;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * Unit tests for {@link RunListenerAdapter}.
+ *
+ * @since 1.0
+ */
+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() {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
new file mode 100644
index 0000000..3a52590
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import org.junit.platform.runner.IncludeClassNamePatterns;
+import org.junit.platform.runner.IncludeEngines;
+import org.junit.platform.runner.JUnitPlatform;
+import org.junit.platform.runner.SelectPackages;
+import org.junit.runner.RunWith;
+
+/**
+ * Test suite for the JUnit Platform Surefire Provider.
+ *
+ * <h3>Logging Configuration</h3>
+ *
+ * <p>In order for our log4j2 configuration to be used in an IDE, you must
+ * set the following system property before running any tests — for
+ * example, in <em>Run Configurations</em> in Eclipse.
+ *
+ * <pre class="code">
+ * -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
+ * </pre>
+ *
+ * @since 1.0
+ */
+@RunWith(JUnitPlatform.class)
+@SelectPackages("org.junit.platform.surefire.provider")
+@IncludeClassNamePatterns(".*Tests?")
+@IncludeEngines("junit-jupiter")
+public class SurefireProviderTestSuite {
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..bd48d66
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2015-2017 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.junit.platform.surefire.provider;
+
+import static java.util.Collections.emptyList;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.DynamicTest;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestFactory;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.core.LauncherFactory;
+
+/**
+ * Unit tests for {@link TestPlanScannerFilter}.
+ *
+ * @since 1.0
+ */
+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 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 {
+
+ @TestFactory
+ List<DynamicTest> tests() {
+ return emptyList();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/73e09a8b/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
new file mode 100644
index 0000000..27875d9
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml
@@ -0,0 +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
[16/16] maven-surefire git commit: Add contributors of the original
provider implementation to pom.xml
Posted by ti...@apache.org.
Add contributors of the original provider implementation to pom.xml
Thank you for your contributions to open source:
- @lutovich
- @hotchemi
- @sbrannen
- @bechte
- @marcphilipp
- @mmerdes
- @jlink
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/c9a1f973
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/c9a1f973
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/c9a1f973
Branch: refs/heads/3.0-rc1
Commit: c9a1f973e334b402d59f9944c5a58d1db9c8da45
Parents: 6e83aa3
Author: Benedikt Ritter <br...@apache.org>
Authored: Fri Feb 10 21:00:14 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Fri Feb 10 21:00:14 2017 +0100
----------------------------------------------------------------------
.../surefire-junit-platform/pom.xml | 45 ++++++++++++++++++++
1 file changed, 45 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c9a1f973/surefire-providers/surefire-junit-platform/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/pom.xml b/surefire-providers/surefire-junit-platform/pom.xml
index 9e5cedd..a4287bf 100644
--- a/surefire-providers/surefire-junit-platform/pom.xml
+++ b/surefire-providers/surefire-junit-platform/pom.xml
@@ -139,4 +139,49 @@
</plugin>
</plugins>
</build>
+
+ <contributors>
+ <contributor>
+ <name>Konstantin Lutovich</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ <contributor>
+ <name>Shintaro Katafuchi</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ <contributor>
+ <name>Sam Brannen</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ <contributor>
+ <name>Stefan Bechtold</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ <contributor>
+ <name>Marc Philipp</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ <contributor>
+ <name>Matthias Merdes</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ <contributor>
+ <name>Johannes Link</name>
+ <roles>
+ <role>Contributed to the original provider implementation</role>
+ </roles>
+ </contributor>
+ </contributors>
</project>
[14/16] maven-surefire git commit: Rename JUnit5 provider to JUnit
Platform provider, as suggested by @marcphilipp
Posted by ti...@apache.org.
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java
deleted file mode 100644
index 5518b29..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java
+++ /dev/null
@@ -1,262 +0,0 @@
-package org.apache.maven.surefire.junit5;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static java.util.Collections.singletonList;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Optional;
-
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.RunListener;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
-import org.junit.jupiter.engine.descriptor.MethodTestDescriptor;
-import org.junit.platform.engine.TestDescriptor;
-import org.junit.platform.engine.TestExecutionResult;
-import org.junit.platform.engine.UniqueId;
-import org.junit.platform.engine.support.descriptor.EngineDescriptor;
-import org.junit.platform.launcher.TestIdentifier;
-import org.junit.platform.launcher.TestPlan;
-import org.mockito.ArgumentCaptor;
-
-/**
- * Unit tests for {@link RunListenerAdapter}.
- *
- * @since 1.0
- */
-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( 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/6e83aa38/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java
deleted file mode 100644
index aa52b78..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package org.apache.maven.surefire.junit5;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static java.util.Collections.emptyList;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.List;
-import java.util.stream.Stream;
-
-import org.junit.jupiter.api.DynamicTest;
-import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestFactory;
-import org.junit.platform.engine.Filter;
-import org.junit.platform.launcher.core.LauncherFactory;
-
-/**
- * Unit tests for {@link TestPlanScannerFilter}.
- *
- * @since 1.0
- */
-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 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
- {
-
- @TestFactory
- List<DynamicTest> tests()
- {
- return emptyList();
- }
- }
- }
-
-}
[09/16] maven-surefire git commit: Move provider classes to maven
surefire package
Posted by ti...@apache.org.
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/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
deleted file mode 100644
index f9e9ca4..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/TestPlanScannerFilterTests.java
+++ /dev/null
@@ -1,190 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static java.util.Collections.emptyList;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.util.List;
-import java.util.stream.Stream;
-
-import org.junit.jupiter.api.DynamicTest;
-import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.TestFactory;
-import org.junit.platform.engine.Filter;
-import org.junit.platform.launcher.core.LauncherFactory;
-
-/**
- * Unit tests for {@link TestPlanScannerFilter}.
- *
- * @since 1.0
- */
-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 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
- {
-
- @TestFactory
- List<DynamicTest> tests()
- {
- return emptyList();
- }
- }
- }
-
-}
[08/16] maven-surefire git commit: Remove usage of internal JUnit API
Posted by ti...@apache.org.
Remove usage of internal JUnit API
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/30ee7b94
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/30ee7b94
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/30ee7b94
Branch: refs/heads/3.0-rc1
Commit: 30ee7b94c3421411aa6257e78f77fe8b88aa125e
Parents: 43fb41e
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 19:06:23 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 19:06:23 2017 +0100
----------------------------------------------------------------------
surefire-providers/surefire-junit5/pom.xml | 2 --
.../provider/JUnitPlatformProvider.java | 28 +++++++++++---------
2 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/30ee7b94/surefire-providers/surefire-junit5/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/pom.xml b/surefire-providers/surefire-junit5/pom.xml
index 55099f5..cf25aa2 100644
--- a/surefire-providers/surefire-junit5/pom.xml
+++ b/surefire-providers/surefire-junit5/pom.xml
@@ -43,8 +43,6 @@
<artifactId>junit-platform-launcher</artifactId>
<version>${junit-platform.version}</version>
</dependency>
- <!-- FIXME: dependency is currenlty needed in scope compile because the initial implementation uses the internal
- Preconditions class -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/30ee7b94/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 066185f..3ee8acb 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
@@ -19,17 +19,6 @@ package org.junit.platform.surefire.provider;
* under the License.
*/
-import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
-import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
import org.apache.maven.surefire.providerapi.AbstractProvider;
import org.apache.maven.surefire.providerapi.ProviderParameters;
import org.apache.maven.surefire.report.ReporterException;
@@ -39,13 +28,23 @@ import org.apache.maven.surefire.report.SimpleReportEntry;
import org.apache.maven.surefire.suite.RunResult;
import org.apache.maven.surefire.testset.TestSetFailedException;
import org.apache.maven.surefire.util.TestsToRun;
-import org.junit.platform.commons.util.Preconditions;
import org.junit.platform.engine.Filter;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.TagFilter;
import org.junit.platform.launcher.core.LauncherFactory;
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
/**
* @since 1.0
*/
@@ -183,7 +182,10 @@ public class JUnitPlatformProvider
{
Optional<List<String>> elements = Optional.empty();
- Preconditions.condition( !groups.isPresent() || !tags.isPresent(), EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED );
+ if ( groups.isPresent() && tags.isPresent() )
+ {
+ throw new IllegalStateException( EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED );
+ }
if ( groups.isPresent() )
{
[11/16] maven-surefire git commit: Remove engine declaration - this
should be done automatically by surefire
Posted by ti...@apache.org.
Remove engine declaration - this should be done automatically by surefire
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/97f97167
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/97f97167
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/97f97167
Branch: refs/heads/3.0-rc1
Commit: 97f97167ea0aa07bba4bd864b1f686c2f79ca33d
Parents: c197b92
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 19:17:36 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 19:17:36 2017 +0100
----------------------------------------------------------------------
surefire-providers/surefire-junit5/pom.xml | 12 ------------
1 file changed, 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/97f97167/surefire-providers/surefire-junit5/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/pom.xml b/surefire-providers/surefire-junit5/pom.xml
index cf25aa2..ec318d5 100644
--- a/surefire-providers/surefire-junit5/pom.xml
+++ b/surefire-providers/surefire-junit5/pom.xml
@@ -116,18 +116,6 @@
<configuration>
<jvm>${java.home}/bin/java</jvm>
</configuration>
- <dependencies>
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-surefire-provider</artifactId>
- <version>${junit-platform.version}</version>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${junit-jupiter.version}</version>
- </dependency>
- </dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
[07/16] maven-surefire git commit: Remove unused filed
Posted by ti...@apache.org.
Remove unused filed
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/43fb41e8
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/43fb41e8
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/43fb41e8
Branch: refs/heads/3.0-rc1
Commit: 43fb41e8d4115830fbeb6d29f1f17efe8e04de5f
Parents: caceca1
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 18:56:20 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 18:56:20 2017 +0100
----------------------------------------------------------------------
.../src/test/resources/log4j2-test.xml | 33 --------------------
1 file changed, 33 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/43fb41e8/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
deleted file mode 100644
index 7747265..0000000
--- a/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml
+++ /dev/null
@@ -1,33 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- -->
-<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>
[03/16] maven-surefire git commit: Convert spaces to tabs
Posted by ti...@apache.org.
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 <br...@apache.org>
Authored: Mon Feb 6 14:23:03 2017 +0100
Committer: Benedikt Ritter <br...@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>
[13/16] maven-surefire git commit: Configure shade plugin so that is
does not explode
Posted by ti...@apache.org.
Configure shade plugin so that is does not explode
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/ef6a3910
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/ef6a3910
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/ef6a3910
Branch: refs/heads/3.0-rc1
Commit: ef6a391006ab1fa672dc26fc234b6411a7dfa888
Parents: b08b1ae
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 19:54:59 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 19:54:59 2017 +0100
----------------------------------------------------------------------
surefire-providers/surefire-junit5/pom.xml | 10 ----------
1 file changed, 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ef6a3910/surefire-providers/surefire-junit5/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/pom.xml b/surefire-providers/surefire-junit5/pom.xml
index ec318d5..54d5fcf 100644
--- a/surefire-providers/surefire-junit5/pom.xml
+++ b/surefire-providers/surefire-junit5/pom.xml
@@ -128,21 +128,11 @@
<goal>shade</goal>
</goals>
<configuration>
- <minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
- <include>org.apache.maven.surefire:common-junit3</include>
- <include>org.apache.maven.surefire:common-junit4</include>
<include>org.apache.maven.surefire:common-java5</include>
- <include>org.apache.maven.shared:maven-shared-utils</include>
</includes>
</artifactSet>
- <relocations>
- <relocation>
- <pattern>org.apache.maven.shared</pattern>
- <shadedPattern>org.apache.maven.surefire.shade.org.apache.maven.shared</shadedPattern>
- </relocation>
- </relocations>
</configuration>
</execution>
</executions>
[06/16] maven-surefire git commit: Add surefire-junit5 provider as
module to the surefire build
Posted by ti...@apache.org.
Add surefire-junit5 provider as module to the surefire build
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/caceca16
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/caceca16
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/caceca16
Branch: refs/heads/3.0-rc1
Commit: caceca16772c6d11302c2d8627c7f5b7d913878a
Parents: 9283dee
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 18:55:49 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 18:55:49 2017 +0100
----------------------------------------------------------------------
surefire-providers/pom.xml | 1 +
surefire-providers/surefire-junit5/pom.xml | 166 +++++++++++++++++++
.../surefire/provider/RunListenerAdapter.java | 4 +-
.../provider/SurefireProviderTestSuite.java | 49 ------
4 files changed, 169 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/caceca16/surefire-providers/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/pom.xml b/surefire-providers/pom.xml
index a90d50d..894a157 100644
--- a/surefire-providers/pom.xml
+++ b/surefire-providers/pom.xml
@@ -41,6 +41,7 @@
<module>surefire-junit3</module>
<module>surefire-junit4</module>
<module>surefire-junit47</module>
+ <module>surefire-junit5</module>
<module>surefire-testng-utils</module>
<module>surefire-testng</module>
</modules>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/caceca16/surefire-providers/surefire-junit5/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/pom.xml b/surefire-providers/surefire-junit5/pom.xml
new file mode 100644
index 0000000..55099f5
--- /dev/null
+++ b/surefire-providers/surefire-junit5/pom.xml
@@ -0,0 +1,166 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-providers</artifactId>
+ <version>2.19.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>surefire-junit5</artifactId>
+
+ <name>SureFire JUnit5 Runner</name>
+ <description>SureFire JUnit 5.0+ Runner</description>
+
+ <properties>
+ <javaVersion>8</javaVersion>
+ <junit-platform.version>1.0.0-M3</junit-platform.version>
+ <junit-jupiter.version>5.0.0-M3</junit-jupiter.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-launcher</artifactId>
+ <version>${junit-platform.version}</version>
+ </dependency>
+ <!-- FIXME: dependency is currenlty needed in scope compile because the initial implementation uses the internal
+ Preconditions class -->
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-engine</artifactId>
+ <version>${junit-platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>common-java5</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit-jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit-jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.2.22</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.6.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources/META-INF</directory>
+ <targetPath>META-INF</targetPath>
+ </resource>
+ </resources>
+
+ <plugins>
+ <!-- Override default configuration for Java 1.6 -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
+ <version>1.14</version>
+ <executions>
+ <execution>
+ <id>signature-check</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <signature>
+ <groupId>org.codehaus.mojo.signature</groupId>
+ <artifactId>java18</artifactId>
+ <version>1.0</version>
+ </signature>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <jvm>${java.home}/bin/java</jvm>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-surefire-provider</artifactId>
+ <version>${junit-platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit-jupiter.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <minimizeJar>true</minimizeJar>
+ <artifactSet>
+ <includes>
+ <include>org.apache.maven.surefire:common-junit3</include>
+ <include>org.apache.maven.surefire:common-junit4</include>
+ <include>org.apache.maven.surefire:common-java5</include>
+ <include>org.apache.maven.shared:maven-shared-utils</include>
+ </includes>
+ </artifactSet>
+ <relocations>
+ <relocation>
+ <pattern>org.apache.maven.shared</pattern>
+ <shadedPattern>org.apache.maven.surefire.shade.org.apache.maven.shared</shadedPattern>
+ </relocation>
+ </relocations>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/caceca16/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 a7d8489..6319a14 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
@@ -106,11 +106,11 @@ final class RunListenerAdapter
{
StackTraceWriter traceWriter = new PojoStackTraceWriter( className.get(),
getMethodName( testIdentifier ).orElse( "" ), throwable.orElse( null ) );
- return new SimpleReportEntry( className.get(), testIdentifier.getDisplayName(), traceWriter, null );
+ return new SimpleReportEntry( className.get(), testIdentifier.getDisplayName(), traceWriter, (Integer) null );
}
else
{
- return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(), null );
+ return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(), (Integer) null );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/caceca16/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
deleted file mode 100644
index 2d76e71..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.junit.platform.runner.IncludeClassNamePatterns;
-import org.junit.platform.runner.IncludeEngines;
-import org.junit.platform.runner.JUnitPlatform;
-import org.junit.platform.runner.SelectPackages;
-import org.junit.runner.RunWith;
-
-/**
- * Test suite for the JUnit Platform Surefire Provider.
- *
- * <h3>Logging Configuration</h3>
- *
- * <p>In order for our log4j2 configuration to be used in an IDE, you must
- * set the following system property before running any tests — for
- * example, in <em>Run Configurations</em> in Eclipse.
- *
- * <pre class="code">
- * -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager
- * </pre>
- *
- * @since 1.0
- */
-@RunWith( JUnitPlatform.class )
-@SelectPackages( "org.junit.platform.surefire.provider" )
-@IncludeClassNamePatterns( ".*Tests?" )
-@IncludeEngines( "junit-jupiter" )
-public class SurefireProviderTestSuite
-{
-}
[10/16] maven-surefire git commit: Move provider classes to maven
surefire package
Posted by ti...@apache.org.
Move provider classes to maven surefire package
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/c197b926
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/c197b926
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/c197b926
Branch: refs/heads/3.0-rc1
Commit: c197b926a5f02ab2a3842d4a8a736315c3c8eb33
Parents: 30ee7b9
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 19:14:53 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 19:14:53 2017 +0100
----------------------------------------------------------------------
.../surefire/junit5/JUnitPlatformProvider.java | 202 ++++++++++++
.../surefire/junit5/RunListenerAdapter.java | 148 +++++++++
.../surefire/junit5/TestPlanScannerFilter.java | 64 ++++
.../provider/JUnitPlatformProvider.java | 202 ------------
.../surefire/provider/RunListenerAdapter.java | 148 ---------
.../provider/TestPlanScannerFilter.java | 64 ----
....maven.surefire.providerapi.SurefireProvider | 2 +-
.../junit5/JUnitPlatformProviderTests.java | 325 +++++++++++++++++++
.../junit5/RunListenerAdapterTests.java | 262 +++++++++++++++
.../junit5/TestPlanScannerFilterTests.java | 190 +++++++++++
.../provider/JUnitPlatformProviderTests.java | 325 -------------------
.../provider/RunListenerAdapterTests.java | 263 ---------------
.../provider/TestPlanScannerFilterTests.java | 190 -----------
13 files changed, 1192 insertions(+), 1193 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java
new file mode 100644
index 0000000..ee93165
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java
@@ -0,0 +1,202 @@
+package org.apache.maven.surefire.junit5;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.providerapi.AbstractProvider;
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.TagFilter;
+import org.junit.platform.launcher.core.LauncherFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
+/**
+ * @since 1.0
+ */
+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();
+
+ if ( groups.isPresent() && tags.isPresent() )
+ {
+ throw new IllegalStateException( 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/c197b926/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
new file mode 100644
index 0000000..8e1a2e2
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
@@ -0,0 +1,148 @@
+package org.apache.maven.surefire.junit5;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
+import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
+import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
+
+import java.util.Optional;
+
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.TestSource;
+import org.junit.platform.engine.support.descriptor.ClassSource;
+import org.junit.platform.engine.support.descriptor.MethodSource;
+import org.junit.platform.launcher.TestExecutionListener;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+
+/**
+ * @since 1.0
+ */
+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, (Integer) null );
+ }
+ else
+ {
+ return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(), (Integer) 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 )
+ {
+ return testPlan
+ .flatMap( plan -> plan.getParent( testIdentifier ) )
+ .map( TestIdentifier::getDisplayName )
+ .orElseGet( testIdentifier::getUniqueId );
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java
new file mode 100644
index 0000000..123c58d
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java
@@ -0,0 +1,64 @@
+package org.apache.maven.surefire.junit5;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
+import java.util.function.Predicate;
+
+import org.apache.maven.surefire.util.ScannerFilter;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+
+/**
+ * @since 1.0
+ */
+final class TestPlanScannerFilter
+ implements ScannerFilter
+{
+
+ private static final Predicate<TestIdentifier> HAS_TESTS = 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( HAS_TESTS ) > 0;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/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
deleted file mode 100644
index 3ee8acb..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/JUnitPlatformProvider.java
+++ /dev/null
@@ -1,202 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.surefire.providerapi.AbstractProvider;
-import org.apache.maven.surefire.providerapi.ProviderParameters;
-import org.apache.maven.surefire.report.ReporterException;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.RunListener;
-import org.apache.maven.surefire.report.SimpleReportEntry;
-import org.apache.maven.surefire.suite.RunResult;
-import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.TestsToRun;
-import org.junit.platform.engine.Filter;
-import org.junit.platform.launcher.Launcher;
-import org.junit.platform.launcher.LauncherDiscoveryRequest;
-import org.junit.platform.launcher.TagFilter;
-import org.junit.platform.launcher.core.LauncherFactory;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
-import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
-
-/**
- * @since 1.0
- */
-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();
-
- if ( groups.isPresent() && tags.isPresent() )
- {
- throw new IllegalStateException( 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/c197b926/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
deleted file mode 100644
index 6319a14..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/RunListenerAdapter.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
-import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
-import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
-
-import java.util.Optional;
-
-import org.apache.maven.surefire.report.PojoStackTraceWriter;
-import org.apache.maven.surefire.report.RunListener;
-import org.apache.maven.surefire.report.SimpleReportEntry;
-import org.apache.maven.surefire.report.StackTraceWriter;
-import org.junit.platform.engine.TestExecutionResult;
-import org.junit.platform.engine.TestSource;
-import org.junit.platform.engine.support.descriptor.ClassSource;
-import org.junit.platform.engine.support.descriptor.MethodSource;
-import org.junit.platform.launcher.TestExecutionListener;
-import org.junit.platform.launcher.TestIdentifier;
-import org.junit.platform.launcher.TestPlan;
-
-/**
- * @since 1.0
- */
-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, (Integer) null );
- }
- else
- {
- return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(), (Integer) 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 )
- {
- return testPlan
- .flatMap( plan -> plan.getParent( testIdentifier ) )
- .map( TestIdentifier::getDisplayName )
- .orElseGet( testIdentifier::getUniqueId );
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/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
deleted file mode 100644
index 12edea0..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/TestPlanScannerFilter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
-import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
-
-import java.util.function.Predicate;
-
-import org.apache.maven.surefire.util.ScannerFilter;
-import org.junit.platform.engine.Filter;
-import org.junit.platform.launcher.Launcher;
-import org.junit.platform.launcher.LauncherDiscoveryRequest;
-import org.junit.platform.launcher.TestIdentifier;
-import org.junit.platform.launcher.TestPlan;
-
-/**
- * @since 1.0
- */
-final class TestPlanScannerFilter
- implements ScannerFilter
-{
-
- private static final Predicate<TestIdentifier> HAS_TESTS = 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( HAS_TESTS ) > 0;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider b/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
index bb76525..44861d6 100644
--- a/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
+++ b/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
@@ -1 +1 @@
-org.junit.platform.surefire.provider.JUnitPlatformProvider
+org.apache.maven.surefire.junit5.JUnitPlatformProvider
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java
new file mode 100644
index 0000000..cce0755
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java
@@ -0,0 +1,325 @@
+package org.apache.maven.surefire.junit5;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.util.RunOrderCalculator;
+import org.apache.maven.surefire.util.ScanResult;
+import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.platform.commons.util.PreconditionViolationException;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.TestPlan;
+import org.junit.platform.launcher.core.LauncherFactory;
+import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
+import org.junit.platform.launcher.listeners.TestExecutionSummary;
+
+/**
+ * Unit tests for {@link JUnitPlatformProvider}.
+ *
+ * @since 1.0
+ */
+class JUnitPlatformProviderTests
+{
+
+ @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 );
+
+ assertThrows( IllegalArgumentException.class, () -> provider.invoke( "wrong forkTestSet" ) );
+ }
+
+ @Test
+ void allGivenTestsToRunAreInvoked()
+ throws Exception
+ {
+ Launcher launcher = LauncherFactory.create();
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners( executionListener );
+
+ 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 ) );
+ }
+
+ @Test
+ void singleTestClassIsInvoked()
+ throws Exception
+ {
+ Launcher launcher = LauncherFactory.create();
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners( executionListener );
+
+ provider.invoke( TestClass1.class );
+
+ 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 );
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners( executionListener );
+
+ provider.invoke( null );
+
+ 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 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" );
+
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+ when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ assertEquals( 1, provider.includeAndExcludeFilters.length );
+ }
+
+ @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 );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ 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" );
+
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+ when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ assertEquals( 2, provider.includeAndExcludeFilters.length );
+ }
+
+ @Test
+ void noFiltersAreCreatedIfNoPropertiesAreDeclared()
+ throws Exception
+ {
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ 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<>();
+
+ @Override
+ public void testPlanExecutionFinished( TestPlan testPlan )
+ {
+ super.testPlanExecutionFinished( testPlan );
+ summaries.add( getSummary() );
+ }
+ }
+
+ private static class TestClass1
+ {
+
+ @Test
+ void test1()
+ {
+ }
+
+ @Test
+ void test2()
+ {
+ }
+
+ @Disabled
+ @Test
+ void test3()
+ {
+ }
+
+ @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() );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java
new file mode 100644
index 0000000..5518b29
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/RunListenerAdapterTests.java
@@ -0,0 +1,262 @@
+package org.apache.maven.surefire.junit5;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.util.Collections.singletonList;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.RunListener;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
+import org.junit.jupiter.engine.descriptor.MethodTestDescriptor;
+import org.junit.platform.engine.TestDescriptor;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.UniqueId;
+import org.junit.platform.engine.support.descriptor.EngineDescriptor;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * Unit tests for {@link RunListenerAdapter}.
+ *
+ * @since 1.0
+ */
+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( 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/c197b926/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java
new file mode 100644
index 0000000..aa52b78
--- /dev/null
+++ b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/TestPlanScannerFilterTests.java
@@ -0,0 +1,190 @@
+package org.apache.maven.surefire.junit5;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.util.Collections.emptyList;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.DynamicTest;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestFactory;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.core.LauncherFactory;
+
+/**
+ * Unit tests for {@link TestPlanScannerFilter}.
+ *
+ * @since 1.0
+ */
+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 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
+ {
+
+ @TestFactory
+ List<DynamicTest> tests()
+ {
+ return emptyList();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/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
deleted file mode 100644
index 9cc054d..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/JUnitPlatformProviderTests.java
+++ /dev/null
@@ -1,325 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.maven.surefire.providerapi.ProviderParameters;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.RunListener;
-import org.apache.maven.surefire.util.RunOrderCalculator;
-import org.apache.maven.surefire.util.ScanResult;
-import org.apache.maven.surefire.util.TestsToRun;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.junit.platform.commons.util.PreconditionViolationException;
-import org.junit.platform.launcher.Launcher;
-import org.junit.platform.launcher.TestPlan;
-import org.junit.platform.launcher.core.LauncherFactory;
-import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
-import org.junit.platform.launcher.listeners.TestExecutionSummary;
-
-/**
- * Unit tests for {@link JUnitPlatformProvider}.
- *
- * @since 1.0
- */
-class JUnitPlatformProviderTests
-{
-
- @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 );
-
- assertThrows( IllegalArgumentException.class, () -> provider.invoke( "wrong forkTestSet" ) );
- }
-
- @Test
- void allGivenTestsToRunAreInvoked()
- throws Exception
- {
- Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
-
- TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners( executionListener );
-
- 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 ) );
- }
-
- @Test
- void singleTestClassIsInvoked()
- throws Exception
- {
- Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
-
- TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners( executionListener );
-
- provider.invoke( TestClass1.class );
-
- 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 );
-
- TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners( executionListener );
-
- provider.invoke( null );
-
- 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 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" );
-
- ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
- when( providerParameters.getProviderProperties() ).thenReturn( properties );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- assertEquals( 1, provider.includeAndExcludeFilters.length );
- }
-
- @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 );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- 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" );
-
- ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
- when( providerParameters.getProviderProperties() ).thenReturn( properties );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- assertEquals( 2, provider.includeAndExcludeFilters.length );
- }
-
- @Test
- void noFiltersAreCreatedIfNoPropertiesAreDeclared()
- throws Exception
- {
- ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- 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<>();
-
- @Override
- public void testPlanExecutionFinished( TestPlan testPlan )
- {
- super.testPlanExecutionFinished( testPlan );
- summaries.add( getSummary() );
- }
- }
-
- private static class TestClass1
- {
-
- @Test
- void test1()
- {
- }
-
- @Test
- void test2()
- {
- }
-
- @Disabled
- @Test
- void test3()
- {
- }
-
- @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() );
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/c197b926/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
deleted file mode 100644
index e841b53..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/RunListenerAdapterTests.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package org.junit.platform.surefire.provider;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static java.util.Collections.singletonList;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.Collections;
-import java.util.Optional;
-
-import org.apache.maven.surefire.report.ReportEntry;
-import org.apache.maven.surefire.report.RunListener;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
-import org.junit.jupiter.engine.descriptor.MethodTestDescriptor;
-import org.junit.platform.engine.TestDescriptor;
-import org.junit.platform.engine.TestExecutionResult;
-import org.junit.platform.engine.UniqueId;
-import org.junit.platform.engine.support.descriptor.EngineDescriptor;
-import org.junit.platform.launcher.TestIdentifier;
-import org.junit.platform.launcher.TestPlan;
-import org.mockito.ArgumentCaptor;
-
-/**
- * Unit tests for {@link RunListenerAdapter}.
- *
- * @since 1.0
- */
-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( 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()
- {
- }
-
- }
-
-}
[02/16] maven-surefire git commit: Remove LICENSE file,
ALv2 will be part of the source distribution
Posted by ti...@apache.org.
Remove LICENSE file, ALv2 will be part of the source distribution
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/0c329812
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/0c329812
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/0c329812
Branch: refs/heads/3.0-rc1
Commit: 0c329812e71f149bb7c92bfaa3fa37c6d2ec6eec
Parents: 73e09a8
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 14:20:54 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 14:20:54 2017 +0100
----------------------------------------------------------------------
surefire-providers/surefire-junit5/LICENSE.md | 194 ---------------------
1 file changed, 194 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/0c329812/surefire-providers/surefire-junit5/LICENSE.md
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/LICENSE.md b/surefire-providers/surefire-junit5/LICENSE.md
deleted file mode 100644
index b62a9b5..0000000
--- a/surefire-providers/surefire-junit5/LICENSE.md
+++ /dev/null
@@ -1,194 +0,0 @@
-Apache License
-==============
-
-_Version 2.0, January 2004_
-_<<http://www.apache.org/licenses/>>_
-
-### Terms and Conditions for use, reproduction, and distribution
-
-#### 1. Definitions
-
-\u201cLicense\u201d shall mean the terms and conditions for use, reproduction, and
-distribution as defined by Sections 1 through 9 of this document.
-
-\u201cLicensor\u201d shall mean the copyright owner or entity authorized by the copyright
-owner that is granting the License.
-
-\u201cLegal Entity\u201d shall mean the union of the acting entity and all other entities
-that control, are controlled by, or are under common control with that entity.
-For the purposes of this definition, \u201ccontrol\u201d means **(i)** the power, direct or
-indirect, to cause the direction or management of such entity, whether by
-contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
-outstanding shares, or **(iii)** beneficial ownership of such entity.
-
-\u201cYou\u201d (or \u201cYour\u201d) shall mean an individual or Legal Entity exercising
-permissions granted by this License.
-
-\u201cSource\u201d form shall mean the preferred form for making modifications, including
-but not limited to software source code, documentation source, and configuration
-files.
-
-\u201cObject\u201d form shall mean any form resulting from mechanical transformation or
-translation of a Source form, including but not limited to compiled object code,
-generated documentation, and conversions to other media types.
-
-\u201cWork\u201d shall mean the work of authorship, whether in Source or Object form, made
-available under the License, as indicated by a copyright notice that is included
-in or attached to the work (an example is provided in the Appendix below).
-
-\u201cDerivative Works\u201d shall mean any work, whether in Source or Object form, that
-is based on (or derived from) the Work and for which the editorial revisions,
-annotations, elaborations, or other modifications represent, as a whole, an
-original work of authorship. For the purposes of this License, Derivative Works
-shall not include works that remain separable from, or merely link (or bind by
-name) to the interfaces of, the Work and Derivative Works thereof.
-
-\u201cContribution\u201d shall mean any work of authorship, including the original version
-of the Work and any modifications or additions to that Work or Derivative Works
-thereof, that is intentionally submitted to Licensor for inclusion in the Work
-by the copyright owner or by an individual or Legal Entity authorized to submit
-on behalf of the copyright owner. For the purposes of this definition,
-\u201csubmitted\u201d means any form of electronic, verbal, or written communication sent
-to the Licensor or its representatives, including but not limited to
-communication on electronic mailing lists, source code control systems, and
-issue tracking systems that are managed by, or on behalf of, the Licensor for
-the purpose of discussing and improving the Work, but excluding communication
-that is conspicuously marked or otherwise designated in writing by the copyright
-owner as \u201cNot a Contribution.\u201d
-
-\u201cContributor\u201d shall mean Licensor and any individual or Legal Entity on behalf
-of whom a Contribution has been received by Licensor and subsequently
-incorporated within the Work.
-
-#### 2. Grant of Copyright License
-
-Subject to the terms and conditions of this License, each Contributor hereby
-grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
-irrevocable copyright license to reproduce, prepare Derivative Works of,
-publicly display, publicly perform, sublicense, and distribute the Work and such
-Derivative Works in Source or Object form.
-
-#### 3. Grant of Patent License
-
-Subject to the terms and conditions of this License, each Contributor hereby
-grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
-irrevocable (except as stated in this section) patent license to make, have
-made, use, offer to sell, sell, import, and otherwise transfer the Work, where
-such license applies only to those patent claims licensable by such Contributor
-that are necessarily infringed by their Contribution(s) alone or by combination
-of their Contribution(s) with the Work to which such Contribution(s) was
-submitted. If You institute patent litigation against any entity (including a
-cross-claim or counterclaim in a lawsuit) alleging that the Work or a
-Contribution incorporated within the Work constitutes direct or contributory
-patent infringement, then any patent licenses granted to You under this License
-for that Work shall terminate as of the date such litigation is filed.
-
-#### 4. Redistribution
-
-You may reproduce and distribute copies of the Work or Derivative Works thereof
-in any medium, with or without modifications, and in Source or Object form,
-provided that You meet the following conditions:
-
-* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
-this License; and
-* **(b)** You must cause any modified files to carry prominent notices stating that You
-changed the files; and
-* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
-all copyright, patent, trademark, and attribution notices from the Source form
-of the Work, excluding those notices that do not pertain to any part of the
-Derivative Works; and
-* **(d)** If the Work includes a \u201cNOTICE\u201d text file as part of its distribution, then any
-Derivative Works that You distribute must include a readable copy of the
-attribution notices contained within such NOTICE file, excluding those notices
-that do not pertain to any part of the Derivative Works, in at least one of the
-following places: within a NOTICE text file distributed as part of the
-Derivative Works; within the Source form or documentation, if provided along
-with the Derivative Works; or, within a display generated by the Derivative
-Works, if and wherever such third-party notices normally appear. The contents of
-the NOTICE file are for informational purposes only and do not modify the
-License. You may add Your own attribution notices within Derivative Works that
-You distribute, alongside or as an addendum to the NOTICE text from the Work,
-provided that such additional attribution notices cannot be construed as
-modifying the License.
-
-You may add Your own copyright statement to Your modifications and may provide
-additional or different license terms and conditions for use, reproduction, or
-distribution of Your modifications, or for any such Derivative Works as a whole,
-provided Your use, reproduction, and distribution of the Work otherwise complies
-with the conditions stated in this License.
-
-#### 5. Submission of Contributions
-
-Unless You explicitly state otherwise, any Contribution intentionally submitted
-for inclusion in the Work by You to the Licensor shall be under the terms and
-conditions of this License, without any additional terms or conditions.
-Notwithstanding the above, nothing herein shall supersede or modify the terms of
-any separate license agreement you may have executed with Licensor regarding
-such Contributions.
-
-#### 6. Trademarks
-
-This License does not grant permission to use the trade names, trademarks,
-service marks, or product names of the Licensor, except as required for
-reasonable and customary use in describing the origin of the Work and
-reproducing the content of the NOTICE file.
-
-#### 7. Disclaimer of Warranty
-
-Unless required by applicable law or agreed to in writing, Licensor provides the
-Work (and each Contributor provides its Contributions) on an \u201cAS IS\u201d BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
-including, without limitation, any warranties or conditions of TITLE,
-NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
-solely responsible for determining the appropriateness of using or
-redistributing the Work and assume any risks associated with Your exercise of
-permissions under this License.
-
-#### 8. Limitation of Liability
-
-In no event and under no legal theory, whether in tort (including negligence),
-contract, or otherwise, unless required by applicable law (such as deliberate
-and grossly negligent acts) or agreed to in writing, shall any Contributor be
-liable to You for damages, including any direct, indirect, special, incidental,
-or consequential damages of any character arising as a result of this License or
-out of the use or inability to use the Work (including but not limited to
-damages for loss of goodwill, work stoppage, computer failure or malfunction, or
-any and all other commercial damages or losses), even if such Contributor has
-been advised of the possibility of such damages.
-
-#### 9. Accepting Warranty or Additional Liability
-
-While redistributing the Work or Derivative Works thereof, You may choose to
-offer, and charge a fee for, acceptance of support, warranty, indemnity, or
-other liability obligations and/or rights consistent with this License. However,
-in accepting such obligations, You may act only on Your own behalf and on Your
-sole responsibility, not on behalf of any other Contributor, and only if You
-agree to indemnify, defend, and hold each Contributor harmless for any liability
-incurred by, or claims asserted against, such Contributor by reason of your
-accepting any such warranty or additional liability.
-
-_END OF TERMS AND CONDITIONS_
-
-### APPENDIX: How to apply the Apache License to your work
-
-To apply the Apache License to your work, attach the following boilerplate
-notice, with the fields enclosed by brackets `[]` replaced with your own
-identifying information. (Don't include the brackets!) The text should be
-enclosed in the appropriate comment syntax for the file format. We also
-recommend that a file or class name and description of purpose be included on
-the same \u201cprinted page\u201d as the copyright notice for easier identification within
-third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
[04/16] maven-surefire git commit: Use Apache Software Foundation
License header
Posted by ti...@apache.org.
Use Apache Software Foundation License header
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/62d00dca
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/62d00dca
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/62d00dca
Branch: refs/heads/3.0-rc1
Commit: 62d00dca5709c0a089a65f810c1c66c2897b5003
Parents: a0d0325
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 14:25:01 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 14:25:01 2017 +0100
----------------------------------------------------------------------
.../provider/JUnitPlatformProvider.java | 25 +++++++++++---------
.../surefire/provider/RunListenerAdapter.java | 25 +++++++++++---------
.../provider/TestPlanScannerFilter.java | 25 +++++++++++---------
.../surefire/provider/package-info.java | 19 ++++++++++++++-
.../provider/JUnitPlatformProviderTests.java | 25 +++++++++++---------
.../provider/RunListenerAdapterTests.java | 25 +++++++++++---------
.../provider/SurefireProviderTestSuite.java | 25 +++++++++++---------
.../provider/TestPlanScannerFilterTests.java | 25 +++++++++++---------
.../src/test/resources/log4j2-test.xml | 18 ++++++++++++++
9 files changed, 134 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 99f0fd5..ff55e0d 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
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 ab79ddd..9c37a29 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
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 29d2f52..9b44d50 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
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
index 29b0c3d..a266633 100644
--- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
+++ b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
@@ -1,5 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
/**
* Maven Surefire provider for the JUnit Platform.
*/
-
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 ef9201a..b09a249 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
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 3b8f34c..9bea40d 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
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
index 3a52590..752d2b5 100644
--- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
+++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 37e6b7f..24ad950 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
@@ -1,17 +1,20 @@
/*
- * Copyright 2015-2017 the original author or authors.
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
*
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
*/
package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/62d00dca/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 c1b215e..7747265 100644
--- a/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml
+++ b/surefire-providers/surefire-junit5/src/test/resources/log4j2-test.xml
@@ -1,4 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
[05/16] maven-surefire git commit: Adopt Apache Maven code style
Posted by ti...@apache.org.
Adopt Apache Maven code style
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/9283dee3
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/9283dee3
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/9283dee3
Branch: refs/heads/3.0-rc1
Commit: 9283dee30decf62e12edd5eaea08abd811ee811f
Parents: 62d00dc
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 15:20:30 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 15:20:30 2017 +0100
----------------------------------------------------------------------
.../provider/JUnitPlatformProvider.java | 129 ++++++----
.../surefire/provider/RunListenerAdapter.java | 109 ++++----
.../provider/TestPlanScannerFilter.java | 27 +-
.../surefire/provider/package-info.java | 22 --
.../provider/JUnitPlatformProviderTests.java | 258 +++++++++++--------
.../provider/RunListenerAdapterTests.java | 213 ++++++++-------
.../provider/SurefireProviderTestSuite.java | 15 +-
.../provider/TestPlanScannerFilterTests.java | 112 +++++---
8 files changed, 512 insertions(+), 373 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/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 ff55e0d..066185f 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
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,6 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
@@ -49,12 +49,17 @@ import org.junit.platform.launcher.core.LauncherFactory;
/**
* @since 1.0
*/
-public class JUnitPlatformProvider extends AbstractProvider {
+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
@@ -62,108 +67,130 @@ public class JUnitPlatformProvider extends AbstractProvider {
+ "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());
+ public JUnitPlatformProvider( ProviderParameters parameters )
+ {
+ this( parameters, LauncherFactory.create() );
}
- JUnitPlatformProvider(ProviderParameters parameters, Launcher launcher) {
+ JUnitPlatformProvider( ProviderParameters parameters, Launcher launcher )
+ {
this.parameters = parameters;
this.launcher = launcher;
this.includeAndExcludeFilters = getIncludeAndExcludeFilters();
- Logger.getLogger("org.junit").setLevel(Level.WARNING);
+ Logger.getLogger( "org.junit" ).setLevel( Level.WARNING );
}
@Override
- public Iterable<Class<?>> getSuites() {
+ public Iterable<Class<?>> getSuites()
+ {
return scanClasspath();
}
@Override
- public RunResult invoke(Object forkTestSet)
- throws TestSetFailedException, ReporterException, InvocationTargetException {
- if (forkTestSet instanceof TestsToRun) {
- return invokeAllTests((TestsToRun) forkTestSet);
+ 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 instanceof Class )
+ {
+ return invokeAllTests( TestsToRun.fromClass( (Class<?>) forkTestSet ) );
}
- else if (forkTestSet == null) {
- return invokeAllTests(scanClasspath());
+ else if ( forkTestSet == null )
+ {
+ return invokeAllTests( scanClasspath() );
}
- else {
- throw new IllegalArgumentException("Unexpected value of forkTestSet: " + forkTestSet);
+ else
+ {
+ throw new IllegalArgumentException( "Unexpected value of forkTestSet: " + forkTestSet );
}
}
- private TestsToRun scanClasspath() {
+ private TestsToRun scanClasspath()
+ {
TestsToRun scannedClasses = parameters.getScanResult().applyFilter(
- new TestPlanScannerFilter(launcher, includeAndExcludeFilters), parameters.getTestClassLoader());
- return parameters.getRunOrderCalculator().orderTestClasses(scannedClasses);
+ new TestPlanScannerFilter( launcher, includeAndExcludeFilters ), parameters.getTestClassLoader() );
+ return parameters.getRunOrderCalculator().orderTestClasses( scannedClasses );
}
- private RunResult invokeAllTests(TestsToRun testsToRun) {
+ private RunResult invokeAllTests( TestsToRun testsToRun )
+ {
RunResult runResult;
ReporterFactory reporterFactory = parameters.getReporterFactory();
- try {
+ try
+ {
RunListener runListener = reporterFactory.createReporter();
- launcher.registerTestExecutionListeners(new RunListenerAdapter(runListener));
+ launcher.registerTestExecutionListeners( new RunListenerAdapter( runListener ) );
- for (Class<?> testClass : testsToRun) {
- invokeSingleClass(testClass, runListener);
+ for ( Class<?> testClass : testsToRun )
+ {
+ invokeSingleClass( testClass, runListener );
}
}
- finally {
+ finally
+ {
runResult = reporterFactory.close();
}
return runResult;
}
- private void invokeSingleClass(Class<?> testClass, RunListener runListener) {
- SimpleReportEntry classEntry = new SimpleReportEntry(getClass().getName(), testClass.getName());
- runListener.testSetStarting(classEntry);
+ 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);
+ LauncherDiscoveryRequest discoveryRequest = request().selectors( selectClass( testClass ) ).filters(
+ includeAndExcludeFilters ).build();
+ launcher.execute( discoveryRequest );
- runListener.testSetCompleted(classEntry);
+ runListener.testSetCompleted( classEntry );
}
- private Filter<?>[] getIncludeAndExcludeFilters() {
+ 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>> 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);
+ 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()]);
+ return filters.toArray( new Filter<?>[filters.size()] );
}
- private Optional<List<String>> getPropertiesList(String key) {
+ 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("[, ]+"));
+ String property = parameters.getProviderProperties().get( key );
+ if ( property != null )
+ {
+ compoundProperties = Arrays.asList( property.split( "[, ]+" ) );
}
- return Optional.ofNullable(compoundProperties);
+ return Optional.ofNullable( compoundProperties );
}
- private Optional<List<String>> getGroupsOrTags(Optional<List<String>> groups, Optional<List<String>> tags) {
+ 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);
+ Preconditions.condition( !groups.isPresent() || !tags.isPresent(), EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED );
- if (groups.isPresent()) {
+ if ( groups.isPresent() )
+ {
elements = groups;
}
- else if (tags.isPresent()) {
+ else if ( tags.isPresent() )
+ {
elements = tags;
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/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 9c37a29..a7d8489 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
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,6 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
@@ -40,88 +40,109 @@ import org.junit.platform.launcher.TestPlan;
/**
* @since 1.0
*/
-final class RunListenerAdapter implements TestExecutionListener {
+final class RunListenerAdapter
+ implements TestExecutionListener
+{
private final RunListener runListener;
+
private Optional<TestPlan> testPlan = Optional.empty();
- public RunListenerAdapter(RunListener runListener) {
+ public RunListenerAdapter( RunListener runListener )
+ {
this.runListener = runListener;
}
@Override
- public void testPlanExecutionStarted(TestPlan testPlan) {
- this.testPlan = Optional.of(testPlan);
+ public void testPlanExecutionStarted( TestPlan testPlan )
+ {
+ this.testPlan = Optional.of( testPlan );
}
@Override
- public void testPlanExecutionFinished(TestPlan testPlan) {
+ public void testPlanExecutionFinished( TestPlan testPlan )
+ {
this.testPlan = Optional.empty();
}
@Override
- public void executionStarted(TestIdentifier testIdentifier) {
- if (testIdentifier.isTest()) {
- runListener.testStarting(createReportEntry(testIdentifier, Optional.empty()));
+ 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));
+ 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()));
+ 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 ( testExecutionResult.getStatus() == FAILED )
+ {
+ runListener.testFailed( createReportEntry( testIdentifier, testExecutionResult.getThrowable() ) );
}
- else if (testIdentifier.isTest()) {
- runListener.testSucceeded(createReportEntry(testIdentifier, Optional.empty()));
+ 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);
+ 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);
+ 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());
+ 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());
+ 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());
+ 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
+ private String parentDisplayName( TestIdentifier testIdentifier )
+ {
return testPlan
- .flatMap(plan -> plan.getParent(testIdentifier))
- .map(TestIdentifier::getDisplayName)
- .orElseGet(testIdentifier::getUniqueId);
- // @formatter:on
+ .flatMap( plan -> plan.getParent( testIdentifier ) )
+ .map( TestIdentifier::getDisplayName )
+ .orElseGet( testIdentifier::getUniqueId );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/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 9b44d50..12edea0 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
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,6 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
@@ -34,26 +34,31 @@ import org.junit.platform.launcher.TestPlan;
/**
* @since 1.0
*/
-final class TestPlanScannerFilter implements ScannerFilter {
+final class TestPlanScannerFilter
+ implements ScannerFilter
+{
- private static final Predicate<TestIdentifier> hasTests = testIdentifier -> testIdentifier.isTest()
+ private static final Predicate<TestIdentifier> HAS_TESTS = testIdentifier -> testIdentifier.isTest()
|| testIdentifier.isContainer();
private final Launcher launcher;
+
private final Filter<?>[] includeAndExcludeFilters;
- public TestPlanScannerFilter(Launcher launcher, 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;
+ @SuppressWarnings( "rawtypes" )
+ public boolean accept( Class testClass )
+ {
+ LauncherDiscoveryRequest discoveryRequest = request().selectors( selectClass( testClass ) ).filters(
+ includeAndExcludeFilters ).build();
+ TestPlan testPlan = launcher.discover( discoveryRequest );
+ return testPlan.countTestIdentifiers( HAS_TESTS ) > 0;
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java b/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
deleted file mode 100644
index a266633..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/junit/platform/surefire/provider/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/**
- * Maven Surefire provider for the JUnit Platform.
- */
-package org.junit.platform.surefire.provider;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/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 b09a249..9cc054d 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
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,6 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -54,76 +54,88 @@ import org.junit.platform.launcher.listeners.TestExecutionSummary;
*
* @since 1.0
*/
-class JUnitPlatformProviderTests {
+class JUnitPlatformProviderTests
+{
@Test
- void getSuitesReturnsScannedClasses() throws Exception {
- ProviderParameters providerParameters = providerParametersMock(TestClass1.class, TestClass2.class);
- JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters);
+ void getSuitesReturnsScannedClasses()
+ throws Exception
+ {
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class, TestClass2.class );
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
- assertThat(provider.getSuites()).containsOnly(TestClass1.class, TestClass2.class);
+ assertThat( provider.getSuites() ).containsOnly( TestClass1.class, TestClass2.class );
}
@Test
- void invokeThrowsForWrongForkTestSet() throws Exception {
- ProviderParameters providerParameters = providerParametersMock(Integer.class);
- JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters);
+ 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 {
+ void allGivenTestsToRunAreInvoked()
+ throws Exception
+ {
Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners(executionListener);
+ 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 {
+ void singleTestClassIsInvoked()
+ throws Exception
+ {
Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParametersMock(), launcher);
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners(executionListener);
+ 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);
+ void allDiscoveredTestsAreInvokedForNullArgument()
+ throws Exception
+ {
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class, TestClass2.class );
Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider(providerParameters, launcher);
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters, launcher );
TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners(executionListener);
+ 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() {
+ void bothGroupsAndIncludeTagsThrowsException()
+ {
Map<String, String> properties = new HashMap<>();
- properties.put(JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo");
- properties.put(JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo");
- verifyPreconditionViolationException(properties);
+ properties.put( JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo" );
+ properties.put( JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo" );
+ verifyPreconditionViolationException( properties );
}
@Test
@@ -135,155 +147,179 @@ class JUnitPlatformProviderTests {
}
@Test
- void onlyGroupsIsDeclared() throws Exception {
+ void onlyGroupsIsDeclared()
+ throws Exception
+ {
Map<String, String> properties = new HashMap<>();
- properties.put(JUnitPlatformProvider.INCLUDE_GROUPS, "groupOne, groupTwo");
+ 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 {
+ void onlyExcludeTagsIsDeclared()
+ throws Exception
+ {
Map<String, String> properties = new HashMap<>();
- properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagOne, tagTwo");
+ 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 {
+ void bothIncludeAndExcludeAreAllowed()
+ throws Exception
+ {
Map<String, String> properties = new HashMap<>();
- properties.put(JUnitPlatformProvider.INCLUDE_TAGS, "tagOne, tagTwo");
- properties.put(JUnitPlatformProvider.EXCLUDE_TAGS, "tagThree, tagFour");
+ 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);
+ 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);
+ 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);
- });
+ Throwable throwable = assertThrows( PreconditionViolationException.class, () ->
+ new JUnitPlatformProvider(providerParameters) );
- assertEquals(JUnitPlatformProvider.EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED, throwable.getMessage());
+ assertEquals( JUnitPlatformProvider.EXCEPTION_MESSAGE_BOTH_NOT_ALLOWED, throwable.getMessage() );
}
- private static ProviderParameters providerParametersMock(Class<?>... testClasses) {
- TestsToRun testsToRun = newTestsToRun(testClasses);
+ private static ProviderParameters providerParametersMock( Class<?>... testClasses )
+ {
+ TestsToRun testsToRun = newTestsToRun( testClasses );
- ScanResult scanResult = mock(ScanResult.class);
- when(scanResult.applyFilter(any(), any())).thenReturn(testsToRun);
+ ScanResult scanResult = mock( ScanResult.class );
+ when( scanResult.applyFilter( any(), any() ) ).thenReturn( testsToRun );
- RunOrderCalculator runOrderCalculator = mock(RunOrderCalculator.class);
- when(runOrderCalculator.orderTestClasses(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);
+ 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);
+ 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 static TestsToRun newTestsToRun( Class<?>... testClasses )
+ {
+ List<Class<?>> classesList = Arrays.asList( testClasses );
+ return new TestsToRun( new LinkedHashSet<>( classesList ) );
}
- private class TestPlanSummaryListener extends SummaryGeneratingListener {
+ private class TestPlanSummaryListener
+ extends SummaryGeneratingListener
+ {
final List<TestExecutionSummary> summaries = new ArrayList<>();
@Override
- public void testPlanExecutionFinished(TestPlan testPlan) {
- super.testPlanExecutionFinished(testPlan);
- summaries.add(getSummary());
+ public void testPlanExecutionFinished( TestPlan testPlan )
+ {
+ super.testPlanExecutionFinished( testPlan );
+ summaries.add( getSummary() );
}
}
- private static class TestClass1 {
+ private static class TestClass1
+ {
@Test
- void test1() {
+ void test1()
+ {
}
@Test
- void test2() {
+ void test2()
+ {
}
@Disabled
@Test
- void test3() {
+ void test3()
+ {
}
@Test
- void test4() {
+ 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());
+ 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 {
+ private static class TestClass2
+ {
@Test
- void test1() {
+ void test1()
+ {
}
@Test
- void test2() {
+ void test2()
+ {
throw new RuntimeException();
}
@Test
- void test3() {
- assumeTrue(false);
+ 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( 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/9283dee3/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 9bea40d..e841b53 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
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,7 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
+import static java.util.Collections.singletonList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -50,173 +51,213 @@ import org.mockito.ArgumentCaptor;
*
* @since 1.0
*/
-class RunListenerAdapterTests {
+class RunListenerAdapterTests
+{
private RunListener listener;
+
private RunListenerAdapter adapter;
@BeforeEach
- public void setUp() {
- listener = mock(RunListener.class);
- adapter = new RunListenerAdapter(listener);
+ public void setUp()
+ {
+ listener = mock( RunListener.class );
+ adapter = new RunListenerAdapter( listener );
}
@Test
- void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exception {
- ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
+ void notifiedWithCorrectNamesWhenMethodExecutionStarted()
+ throws Exception
+ {
+ ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass( ReportEntry.class );
- adapter.executionStarted(newMethodIdentifier());
- verify(listener).testStarting(entryCaptor.capture());
+ 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());
+ 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());
+ 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());
+ 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());
+ void notifiedWhenMethodExecutionSkipped()
+ throws Exception
+ {
+ adapter.executionSkipped( newMethodIdentifier(), "test" );
+ verify( listener ).testSkipped( any() );
}
@Test
- void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception {
- ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass(ReportEntry.class);
+ void notifiedWithCorrectNamesWhenClassExecutionSkipped()
+ throws Exception
+ {
+ ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass( ReportEntry.class );
- adapter.executionSkipped(newClassIdentifier(), "test");
- verify(listener).testSkipped(entryCaptor.capture());
+ 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());
+ 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());
+ 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());
+ 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());
+ 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());
+ 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);
+ void notifiedWithCorrectNamesWhenClassExecutionFailed()
+ throws Exception
+ {
+ ArgumentCaptor<ReportEntry> entryCaptor = ArgumentCaptor.forClass( ReportEntry.class );
- adapter.executionFinished(newClassIdentifier(), TestExecutionResult.failed(new RuntimeException()));
- verify(listener).testFailed(entryCaptor.capture());
+ 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());
+ assertEquals( MyTestClass.class.getName(), entry.getSourceName() );
+ assertNotNull( entry.getStackTraceWriter() );
}
@Test
- void notifiedWhenMethodExecutionSucceeded() throws Exception {
- adapter.executionFinished(newMethodIdentifier(), TestExecutionResult.successful());
- verify(listener).testSucceeded(any());
+ 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());
+ void notNotifiedWhenClassExecutionSucceeded()
+ throws Exception
+ {
+ adapter.executionFinished( newClassIdentifier(), TestExecutionResult.successful() );
+ verify( listener, never() ).testSucceeded( any() );
}
@Test
- void notifiedWithParentDisplayNameWhenTestClassUnknown() throws Exception {
+ void notifiedWithParentDisplayNameWhenTestClassUnknown()
+ throws Exception
+ {
// Set up a test plan
- TestPlan plan = TestPlan.from(Collections.singletonList(new EngineDescriptor(newId(), "Luke's Plan")));
- adapter.testPlanExecutionStarted(plan);
+ TestPlan plan = TestPlan.from( 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);
+ 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());
+ 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 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 newClassIdentifier()
+ {
+ TestDescriptor testDescriptor = new ClassTestDescriptor( newId(), MyTestClass.class );
+ return TestIdentifier.from( testDescriptor );
}
- private static TestIdentifier newSourcelessIdentifierWithParent(TestPlan testPlan, String parentDisplay) {
+ 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);
+ 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);
+ 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);
+ when( child.getSource() ).thenReturn( Optional.empty() );
+ when( child.getParent() ).thenReturn( Optional.of(parent) );
+ TestIdentifier childId = TestIdentifier.from( child );
- testPlan.add(childId);
- testPlan.add(parentId);
+ testPlan.add( childId );
+ testPlan.add( parentId );
return childId;
}
- private static TestIdentifier newEngineIdentifier() {
- TestDescriptor testDescriptor = new EngineDescriptor(newId(), "engine");
- return TestIdentifier.from(testDescriptor);
+ private static TestIdentifier newEngineIdentifier()
+ {
+ TestDescriptor testDescriptor = new EngineDescriptor( newId(), "engine" );
+ return TestIdentifier.from( testDescriptor );
}
- private static UniqueId newId() {
- return UniqueId.forEngine("engine");
+ private static UniqueId newId()
+ {
+ return UniqueId.forEngine( "engine" );
}
private static final String MY_TEST_METHOD_NAME = "myTestMethod";
+
private static class MyTestClass {
+
@Test
- void myTestMethod() {
+ void myTestMethod()
+ {
}
+
}
+
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
index 752d2b5..2d76e71 100644
--- a/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
+++ b/surefire-providers/surefire-junit5/src/test/java/org/junit/platform/surefire/provider/SurefireProviderTestSuite.java
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,6 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
import org.junit.platform.runner.IncludeClassNamePatterns;
import org.junit.platform.runner.IncludeEngines;
import org.junit.platform.runner.JUnitPlatform;
@@ -40,9 +40,10 @@ import org.junit.runner.RunWith;
*
* @since 1.0
*/
-@RunWith(JUnitPlatform.class)
-@SelectPackages("org.junit.platform.surefire.provider")
-@IncludeClassNamePatterns(".*Tests?")
-@IncludeEngines("junit-jupiter")
-public class SurefireProviderTestSuite {
+@RunWith( JUnitPlatform.class )
+@SelectPackages( "org.junit.platform.surefire.provider" )
+@IncludeClassNamePatterns( ".*Tests?" )
+@IncludeEngines( "junit-jupiter" )
+public class SurefireProviderTestSuite
+{
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/9283dee3/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 24ad950..f9e9ca4 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
@@ -1,3 +1,5 @@
+package org.junit.platform.surefire.provider;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -17,8 +19,6 @@
* under the License.
*/
-package org.junit.platform.surefire.provider;
-
import static java.util.Collections.emptyList;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -37,121 +37,151 @@ import org.junit.platform.launcher.core.LauncherFactory;
*
* @since 1.0
*/
-public class TestPlanScannerFilterTests {
+public class TestPlanScannerFilterTests
+{
@Test
- void emptyClassAccepted() {
- assertTrue(newFilter().accept(EmptyClass.class), "accepts empty class because it is a container");
+ 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");
+ 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));
+ void classWithTestMethodsIsAccepted()
+ {
+ assertTrue( newFilter().accept( ClassWithTestMethods.class ) );
}
@Test
- void classWithNestedTestClassIsAccepted() {
- assertTrue(newFilter().accept(ClassWithNestedTestClass.class));
+ void classWithNestedTestClassIsAccepted()
+ {
+ assertTrue( newFilter().accept( ClassWithNestedTestClass.class ) );
}
@Test
- void classWithDeeplyNestedTestClassIsAccepted() {
- assertTrue(newFilter().accept(ClassWithDeeplyNestedTestClass.class));
+ void classWithDeeplyNestedTestClassIsAccepted()
+ {
+ assertTrue( newFilter().accept( ClassWithDeeplyNestedTestClass.class ) );
}
@Test
- void classWithTestFactoryIsAccepted() {
- assertTrue(newFilter().accept(ClassWithTestFactory.class));
+ void classWithTestFactoryIsAccepted()
+ {
+ assertTrue( newFilter().accept( ClassWithTestFactory.class ) );
}
@Test
- void classWithNestedTestFactoryIsAccepted() {
- assertTrue(newFilter().accept(ClassWithNestedTestFactory.class));
+ void classWithNestedTestFactoryIsAccepted()
+ {
+ assertTrue( newFilter().accept( ClassWithNestedTestFactory.class ) );
}
- private TestPlanScannerFilter newFilter() {
- return new TestPlanScannerFilter(LauncherFactory.create(), new Filter<?>[0]);
+ private TestPlanScannerFilter newFilter()
+ {
+ return new TestPlanScannerFilter( LauncherFactory.create(), new Filter<?>[0] );
}
- private static class EmptyClass {
+ private static class EmptyClass
+ {
}
@SuppressWarnings("unused")
- private static class ClassWithMethods {
+ private static class ClassWithMethods
+ {
- void method1() {
+ void method1()
+ {
}
- void method2() {
+ void method2()
+ {
}
}
- private static class ClassWithTestMethods {
+ private static class ClassWithTestMethods
+ {
@Test
- void test1() {
+ void test1()
+ {
}
@Test
- public void test2() {
+ public void test2()
+ {
}
}
- private static class ClassWithNestedTestClass {
+ private static class ClassWithNestedTestClass
+ {
@SuppressWarnings("unused")
- void method() {
+ void method()
+ {
}
@Nested
- class TestClass {
+ class TestClass
+ {
@Test
- void test1() {
+ void test1()
+ {
}
}
}
- private static class ClassWithDeeplyNestedTestClass {
+ private static class ClassWithDeeplyNestedTestClass
+ {
@Nested
- class Level1 {
+ class Level1
+ {
@Nested
- class Level2 {
+ class Level2
+ {
@Nested
- class TestClass {
+ class TestClass
+ {
@Test
- void test1() {
+ void test1()
+ {
}
}
}
}
}
- private static class ClassWithTestFactory {
+ private static class ClassWithTestFactory
+ {
@TestFactory
- Stream<DynamicTest> tests() {
+ Stream<DynamicTest> tests()
+ {
return Stream.empty();
}
}
- private static class ClassWithNestedTestFactory {
+ private static class ClassWithNestedTestFactory
+ {
@Nested
- class TestClass {
+ class TestClass
+ {
@TestFactory
- List<DynamicTest> tests() {
+ List<DynamicTest> tests()
+ {
return emptyList();
}
}
[12/16] maven-surefire git commit: Make Checkstyle happy
Posted by ti...@apache.org.
Make Checkstyle happy
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/b08b1aea
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/b08b1aea
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/b08b1aea
Branch: refs/heads/3.0-rc1
Commit: b08b1aeae4ad01582fd6264462a4a9345bfd065d
Parents: 97f9716
Author: Benedikt Ritter <br...@apache.org>
Authored: Mon Feb 6 19:54:40 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Mon Feb 6 19:54:40 2017 +0100
----------------------------------------------------------------------
.../org/apache/maven/surefire/junit5/RunListenerAdapter.java | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/b08b1aea/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
index 8e1a2e2..4bba78a 100644
--- a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
+++ b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
@@ -106,11 +106,13 @@ final class RunListenerAdapter
{
StackTraceWriter traceWriter = new PojoStackTraceWriter( className.get(),
getMethodName( testIdentifier ).orElse( "" ), throwable.orElse( null ) );
- return new SimpleReportEntry( className.get(), testIdentifier.getDisplayName(), traceWriter, (Integer) null );
+ return new SimpleReportEntry( className.get(), testIdentifier.getDisplayName(), traceWriter,
+ (Integer) null );
}
else
{
- return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(), (Integer) null );
+ return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(),
+ (Integer) null );
}
}
[15/16] maven-surefire git commit: Rename JUnit5 provider to JUnit
Platform provider, as suggested by @marcphilipp
Posted by ti...@apache.org.
Rename JUnit5 provider to JUnit Platform provider, as suggested by @marcphilipp
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/6e83aa38
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/6e83aa38
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/6e83aa38
Branch: refs/heads/3.0-rc1
Commit: 6e83aa3808bcb4accce54a1b1c0ba91dd01a8812
Parents: ef6a391
Author: Benedikt Ritter <br...@apache.org>
Authored: Fri Feb 10 19:59:23 2017 +0100
Committer: Benedikt Ritter <br...@apache.org>
Committed: Fri Feb 10 19:59:23 2017 +0100
----------------------------------------------------------------------
.../surefire-junit-platform/pom.xml | 142 ++++++++
.../junitplatform/JUnitPlatformProvider.java | 202 ++++++++++++
.../junitplatform/RunListenerAdapter.java | 150 +++++++++
.../junitplatform/TestPlanScannerFilter.java | 64 ++++
....maven.surefire.providerapi.SurefireProvider | 1 +
.../JUnitPlatformProviderTests.java | 325 +++++++++++++++++++
.../junitplatform/RunListenerAdapterTests.java | 262 +++++++++++++++
.../TestPlanScannerFilterTests.java | 190 +++++++++++
surefire-providers/surefire-junit5/pom.xml | 142 --------
.../surefire/junit5/JUnitPlatformProvider.java | 202 ------------
.../surefire/junit5/RunListenerAdapter.java | 150 ---------
.../surefire/junit5/TestPlanScannerFilter.java | 64 ----
....maven.surefire.providerapi.SurefireProvider | 1 -
.../junit5/JUnitPlatformProviderTests.java | 325 -------------------
.../junit5/RunListenerAdapterTests.java | 262 ---------------
.../junit5/TestPlanScannerFilterTests.java | 190 -----------
16 files changed, 1336 insertions(+), 1336 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit-platform/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/pom.xml b/surefire-providers/surefire-junit-platform/pom.xml
new file mode 100644
index 0000000..9e5cedd
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/pom.xml
@@ -0,0 +1,142 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied. See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-providers</artifactId>
+ <version>2.19.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>surefire-junit-platform</artifactId>
+
+ <name>SureFire JUnit Platform Runner</name>
+ <description>SureFire JUnit Platform Runner</description>
+
+ <properties>
+ <javaVersion>8</javaVersion>
+ <junit-platform.version>1.0.0-M3</junit-platform.version>
+ <junit-jupiter.version>5.0.0-M3</junit-jupiter.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-launcher</artifactId>
+ <version>${junit-platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.platform</groupId>
+ <artifactId>junit-platform-engine</artifactId>
+ <version>${junit-platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>common-java5</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-api</artifactId>
+ <version>${junit-jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ <version>${junit-jupiter.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>2.2.22</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <version>3.6.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources/META-INF</directory>
+ <targetPath>META-INF</targetPath>
+ </resource>
+ </resources>
+
+ <plugins>
+ <!-- Override default configuration for Java 1.6 -->
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>animal-sniffer-maven-plugin</artifactId>
+ <version>1.14</version>
+ <executions>
+ <execution>
+ <id>signature-check</id>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <signature>
+ <groupId>org.codehaus.mojo.signature</groupId>
+ <artifactId>java18</artifactId>
+ <version>1.0</version>
+ </signature>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <jvm>${java.home}/bin/java</jvm>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-shade-plugin</artifactId>
+ <version>1.4</version>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>shade</goal>
+ </goals>
+ <configuration>
+ <artifactSet>
+ <includes>
+ <include>org.apache.maven.surefire:common-java5</include>
+ </includes>
+ </artifactSet>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
new file mode 100644
index 0000000..7f58921
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java
@@ -0,0 +1,202 @@
+package org.apache.maven.surefire.junitplatform;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.providerapi.AbstractProvider;
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.report.ReporterException;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.suite.RunResult;
+import org.apache.maven.surefire.testset.TestSetFailedException;
+import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.TagFilter;
+import org.junit.platform.launcher.core.LauncherFactory;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
+/**
+ * @since 1.0
+ */
+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();
+
+ if ( groups.isPresent() && tags.isPresent() )
+ {
+ throw new IllegalStateException( 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/6e83aa38/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
new file mode 100644
index 0000000..9191864
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/RunListenerAdapter.java
@@ -0,0 +1,150 @@
+package org.apache.maven.surefire.junitplatform;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
+import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
+import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
+
+import java.util.Optional;
+
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.report.SimpleReportEntry;
+import org.apache.maven.surefire.report.StackTraceWriter;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.TestSource;
+import org.junit.platform.engine.support.descriptor.ClassSource;
+import org.junit.platform.engine.support.descriptor.MethodSource;
+import org.junit.platform.launcher.TestExecutionListener;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+
+/**
+ * @since 1.0
+ */
+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,
+ (Integer) null );
+ }
+ else
+ {
+ return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(),
+ (Integer) 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 )
+ {
+ return testPlan
+ .flatMap( plan -> plan.getParent( testIdentifier ) )
+ .map( TestIdentifier::getDisplayName )
+ .orElseGet( testIdentifier::getUniqueId );
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilter.java b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilter.java
new file mode 100644
index 0000000..4a95d6e
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilter.java
@@ -0,0 +1,64 @@
+package org.apache.maven.surefire.junitplatform;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
+import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
+
+import java.util.function.Predicate;
+
+import org.apache.maven.surefire.util.ScannerFilter;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.LauncherDiscoveryRequest;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+
+/**
+ * @since 1.0
+ */
+final class TestPlanScannerFilter
+ implements ScannerFilter
+{
+
+ private static final Predicate<TestIdentifier> HAS_TESTS = 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( HAS_TESTS ) > 0;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit-platform/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider b/surefire-providers/surefire-junit-platform/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
new file mode 100644
index 0000000..dbe73cf
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
@@ -0,0 +1 @@
+org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTests.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTests.java
new file mode 100644
index 0000000..a32aade
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProviderTests.java
@@ -0,0 +1,325 @@
+package org.apache.maven.surefire.junitplatform;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.surefire.providerapi.ProviderParameters;
+import org.apache.maven.surefire.report.ReporterFactory;
+import org.apache.maven.surefire.report.RunListener;
+import org.apache.maven.surefire.util.RunOrderCalculator;
+import org.apache.maven.surefire.util.ScanResult;
+import org.apache.maven.surefire.util.TestsToRun;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.platform.commons.util.PreconditionViolationException;
+import org.junit.platform.launcher.Launcher;
+import org.junit.platform.launcher.TestPlan;
+import org.junit.platform.launcher.core.LauncherFactory;
+import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
+import org.junit.platform.launcher.listeners.TestExecutionSummary;
+
+/**
+ * Unit tests for {@link JUnitPlatformProvider}.
+ *
+ * @since 1.0
+ */
+class JUnitPlatformProviderTests
+{
+
+ @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 );
+
+ assertThrows( IllegalArgumentException.class, () -> provider.invoke( "wrong forkTestSet" ) );
+ }
+
+ @Test
+ void allGivenTestsToRunAreInvoked()
+ throws Exception
+ {
+ Launcher launcher = LauncherFactory.create();
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners( executionListener );
+
+ 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 ) );
+ }
+
+ @Test
+ void singleTestClassIsInvoked()
+ throws Exception
+ {
+ Launcher launcher = LauncherFactory.create();
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners( executionListener );
+
+ provider.invoke( TestClass1.class );
+
+ 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 );
+
+ TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
+ launcher.registerTestExecutionListeners( executionListener );
+
+ provider.invoke( null );
+
+ 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 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" );
+
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+ when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ assertEquals( 1, provider.includeAndExcludeFilters.length );
+ }
+
+ @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 );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ 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" );
+
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+ when( providerParameters.getProviderProperties() ).thenReturn( properties );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ assertEquals( 2, provider.includeAndExcludeFilters.length );
+ }
+
+ @Test
+ void noFiltersAreCreatedIfNoPropertiesAreDeclared()
+ throws Exception
+ {
+ ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
+
+ JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
+
+ 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<>();
+
+ @Override
+ public void testPlanExecutionFinished( TestPlan testPlan )
+ {
+ super.testPlanExecutionFinished( testPlan );
+ summaries.add( getSummary() );
+ }
+ }
+
+ private static class TestClass1
+ {
+
+ @Test
+ void test1()
+ {
+ }
+
+ @Test
+ void test2()
+ {
+ }
+
+ @Disabled
+ @Test
+ void test3()
+ {
+ }
+
+ @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() );
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTests.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTests.java
new file mode 100644
index 0000000..d05604c
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/RunListenerAdapterTests.java
@@ -0,0 +1,262 @@
+package org.apache.maven.surefire.junitplatform;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.util.Collections.singletonList;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.Optional;
+
+import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.RunListener;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.engine.descriptor.ClassTestDescriptor;
+import org.junit.jupiter.engine.descriptor.MethodTestDescriptor;
+import org.junit.platform.engine.TestDescriptor;
+import org.junit.platform.engine.TestExecutionResult;
+import org.junit.platform.engine.UniqueId;
+import org.junit.platform.engine.support.descriptor.EngineDescriptor;
+import org.junit.platform.launcher.TestIdentifier;
+import org.junit.platform.launcher.TestPlan;
+import org.mockito.ArgumentCaptor;
+
+/**
+ * Unit tests for {@link RunListenerAdapter}.
+ *
+ * @since 1.0
+ */
+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( 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/6e83aa38/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilterTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilterTests.java b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilterTests.java
new file mode 100644
index 0000000..98f5b2b
--- /dev/null
+++ b/surefire-providers/surefire-junit-platform/src/test/java/org/apache/maven/surefire/junitplatform/TestPlanScannerFilterTests.java
@@ -0,0 +1,190 @@
+package org.apache.maven.surefire.junitplatform;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static java.util.Collections.emptyList;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.List;
+import java.util.stream.Stream;
+
+import org.junit.jupiter.api.DynamicTest;
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestFactory;
+import org.junit.platform.engine.Filter;
+import org.junit.platform.launcher.core.LauncherFactory;
+
+/**
+ * Unit tests for {@link TestPlanScannerFilter}.
+ *
+ * @since 1.0
+ */
+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 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
+ {
+
+ @TestFactory
+ List<DynamicTest> tests()
+ {
+ return emptyList();
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit5/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/pom.xml b/surefire-providers/surefire-junit5/pom.xml
deleted file mode 100644
index 54d5fcf..0000000
--- a/surefire-providers/surefire-junit5/pom.xml
+++ /dev/null
@@ -1,142 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one
- ~ or more contributor license agreements. See the NOTICE file
- ~ distributed with this work for additional information
- ~ regarding copyright ownership. The ASF licenses this file
- ~ to you under the Apache License, Version 2.0 (the
- ~ "License"); you may not use this file except in compliance
- ~ with the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing,
- ~ software distributed under the License is distributed on an
- ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- ~ KIND, either express or implied. See the License for the
- ~ specific language governing permissions and limitations
- ~ under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.maven.surefire</groupId>
- <artifactId>surefire-providers</artifactId>
- <version>2.19.2-SNAPSHOT</version>
- </parent>
-
- <artifactId>surefire-junit5</artifactId>
-
- <name>SureFire JUnit5 Runner</name>
- <description>SureFire JUnit 5.0+ Runner</description>
-
- <properties>
- <javaVersion>8</javaVersion>
- <junit-platform.version>1.0.0-M3</junit-platform.version>
- <junit-jupiter.version>5.0.0-M3</junit-jupiter.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-launcher</artifactId>
- <version>${junit-platform.version}</version>
- </dependency>
- <dependency>
- <groupId>org.junit.platform</groupId>
- <artifactId>junit-platform-engine</artifactId>
- <version>${junit-platform.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.maven.surefire</groupId>
- <artifactId>common-java5</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-api</artifactId>
- <version>${junit-jupiter.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.junit.jupiter</groupId>
- <artifactId>junit-jupiter-engine</artifactId>
- <version>${junit-jupiter.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-core</artifactId>
- <version>2.2.22</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.assertj</groupId>
- <artifactId>assertj-core</artifactId>
- <version>3.6.0</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <resources>
- <resource>
- <directory>src/main/resources/META-INF</directory>
- <targetPath>META-INF</targetPath>
- </resource>
- </resources>
-
- <plugins>
- <!-- Override default configuration for Java 1.6 -->
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>animal-sniffer-maven-plugin</artifactId>
- <version>1.14</version>
- <executions>
- <execution>
- <id>signature-check</id>
- <goals>
- <goal>check</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <signature>
- <groupId>org.codehaus.mojo.signature</groupId>
- <artifactId>java18</artifactId>
- <version>1.0</version>
- </signature>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <jvm>${java.home}/bin/java</jvm>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-shade-plugin</artifactId>
- <version>1.4</version>
- <executions>
- <execution>
- <phase>package</phase>
- <goals>
- <goal>shade</goal>
- </goals>
- <configuration>
- <artifactSet>
- <includes>
- <include>org.apache.maven.surefire:common-java5</include>
- </includes>
- </artifactSet>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java
deleted file mode 100644
index ee93165..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/JUnitPlatformProvider.java
+++ /dev/null
@@ -1,202 +0,0 @@
-package org.apache.maven.surefire.junit5;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import org.apache.maven.surefire.providerapi.AbstractProvider;
-import org.apache.maven.surefire.providerapi.ProviderParameters;
-import org.apache.maven.surefire.report.ReporterException;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.RunListener;
-import org.apache.maven.surefire.report.SimpleReportEntry;
-import org.apache.maven.surefire.suite.RunResult;
-import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.TestsToRun;
-import org.junit.platform.engine.Filter;
-import org.junit.platform.launcher.Launcher;
-import org.junit.platform.launcher.LauncherDiscoveryRequest;
-import org.junit.platform.launcher.TagFilter;
-import org.junit.platform.launcher.core.LauncherFactory;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
-import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
-
-/**
- * @since 1.0
- */
-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();
-
- if ( groups.isPresent() && tags.isPresent() )
- {
- throw new IllegalStateException( 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/6e83aa38/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
deleted file mode 100644
index 4bba78a..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/RunListenerAdapter.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.apache.maven.surefire.junit5;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.apache.maven.surefire.report.SimpleReportEntry.ignored;
-import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
-import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
-
-import java.util.Optional;
-
-import org.apache.maven.surefire.report.PojoStackTraceWriter;
-import org.apache.maven.surefire.report.RunListener;
-import org.apache.maven.surefire.report.SimpleReportEntry;
-import org.apache.maven.surefire.report.StackTraceWriter;
-import org.junit.platform.engine.TestExecutionResult;
-import org.junit.platform.engine.TestSource;
-import org.junit.platform.engine.support.descriptor.ClassSource;
-import org.junit.platform.engine.support.descriptor.MethodSource;
-import org.junit.platform.launcher.TestExecutionListener;
-import org.junit.platform.launcher.TestIdentifier;
-import org.junit.platform.launcher.TestPlan;
-
-/**
- * @since 1.0
- */
-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,
- (Integer) null );
- }
- else
- {
- return new SimpleReportEntry( parentDisplayName( testIdentifier ), testIdentifier.getDisplayName(),
- (Integer) 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 )
- {
- return testPlan
- .flatMap( plan -> plan.getParent( testIdentifier ) )
- .map( TestIdentifier::getDisplayName )
- .orElseGet( testIdentifier::getUniqueId );
- }
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java b/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java
deleted file mode 100644
index 123c58d..0000000
--- a/surefire-providers/surefire-junit5/src/main/java/org/apache/maven/surefire/junit5/TestPlanScannerFilter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.apache.maven.surefire.junit5;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
-import static org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder.request;
-
-import java.util.function.Predicate;
-
-import org.apache.maven.surefire.util.ScannerFilter;
-import org.junit.platform.engine.Filter;
-import org.junit.platform.launcher.Launcher;
-import org.junit.platform.launcher.LauncherDiscoveryRequest;
-import org.junit.platform.launcher.TestIdentifier;
-import org.junit.platform.launcher.TestPlan;
-
-/**
- * @since 1.0
- */
-final class TestPlanScannerFilter
- implements ScannerFilter
-{
-
- private static final Predicate<TestIdentifier> HAS_TESTS = 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( HAS_TESTS ) > 0;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider b/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
deleted file mode 100644
index 44861d6..0000000
--- a/surefire-providers/surefire-junit5/src/main/resources/META-INF/services/org.apache.maven.surefire.providerapi.SurefireProvider
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.maven.surefire.junit5.JUnitPlatformProvider
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6e83aa38/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java b/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java
deleted file mode 100644
index cce0755..0000000
--- a/surefire-providers/surefire-junit5/src/test/java/org/apache/maven/surefire/junit5/JUnitPlatformProviderTests.java
+++ /dev/null
@@ -1,325 +0,0 @@
-package org.apache.maven.surefire.junit5;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.junit.jupiter.api.Assumptions.assumeTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.maven.surefire.providerapi.ProviderParameters;
-import org.apache.maven.surefire.report.ReporterFactory;
-import org.apache.maven.surefire.report.RunListener;
-import org.apache.maven.surefire.util.RunOrderCalculator;
-import org.apache.maven.surefire.util.ScanResult;
-import org.apache.maven.surefire.util.TestsToRun;
-import org.junit.jupiter.api.Disabled;
-import org.junit.jupiter.api.Test;
-import org.junit.platform.commons.util.PreconditionViolationException;
-import org.junit.platform.launcher.Launcher;
-import org.junit.platform.launcher.TestPlan;
-import org.junit.platform.launcher.core.LauncherFactory;
-import org.junit.platform.launcher.listeners.SummaryGeneratingListener;
-import org.junit.platform.launcher.listeners.TestExecutionSummary;
-
-/**
- * Unit tests for {@link JUnitPlatformProvider}.
- *
- * @since 1.0
- */
-class JUnitPlatformProviderTests
-{
-
- @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 );
-
- assertThrows( IllegalArgumentException.class, () -> provider.invoke( "wrong forkTestSet" ) );
- }
-
- @Test
- void allGivenTestsToRunAreInvoked()
- throws Exception
- {
- Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
-
- TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners( executionListener );
-
- 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 ) );
- }
-
- @Test
- void singleTestClassIsInvoked()
- throws Exception
- {
- Launcher launcher = LauncherFactory.create();
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParametersMock(), launcher );
-
- TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners( executionListener );
-
- provider.invoke( TestClass1.class );
-
- 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 );
-
- TestPlanSummaryListener executionListener = new TestPlanSummaryListener();
- launcher.registerTestExecutionListeners( executionListener );
-
- provider.invoke( null );
-
- 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 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" );
-
- ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
- when( providerParameters.getProviderProperties() ).thenReturn( properties );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- assertEquals( 1, provider.includeAndExcludeFilters.length );
- }
-
- @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 );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- 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" );
-
- ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
- when( providerParameters.getProviderProperties() ).thenReturn( properties );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- assertEquals( 2, provider.includeAndExcludeFilters.length );
- }
-
- @Test
- void noFiltersAreCreatedIfNoPropertiesAreDeclared()
- throws Exception
- {
- ProviderParameters providerParameters = providerParametersMock( TestClass1.class );
-
- JUnitPlatformProvider provider = new JUnitPlatformProvider( providerParameters );
-
- 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<>();
-
- @Override
- public void testPlanExecutionFinished( TestPlan testPlan )
- {
- super.testPlanExecutionFinished( testPlan );
- summaries.add( getSummary() );
- }
- }
-
- private static class TestClass1
- {
-
- @Test
- void test1()
- {
- }
-
- @Test
- void test2()
- {
- }
-
- @Disabled
- @Test
- void test3()
- {
- }
-
- @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() );
- }
- }
-}