From 87fe5634b438a564fd44752a59b4025833d51a94 Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Thu, 23 May 2019 18:44:10 +0200 Subject: [PATCH 1/8] Introduce support for converting from a URI of the form method: to a MethodSource Introduce support for converting from a URI of the form method: to a MethodSource, where FQMN is the fully qualified method name. See the Javadoc for DiscoverySelectors.selectMethod(String) for the supported formats for a FQMN. Closes gh-1850 --- .../engine/descriptor/MethodSourceUtils.java | 41 +++++++++++++++++++ .../descriptor/TestFactoryTestDescriptor.java | 9 +++- .../TestFactoryTestDescriptorTests.java | 13 ++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java new file mode 100644 index 000000000000..9f7764b0efaa --- /dev/null +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java @@ -0,0 +1,41 @@ +/* + * Copyright 2015-2019 the original author or authors. + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v2.0 which + * accompanies this distribution and is available at + * + * https://www.eclipse.org/legal/epl-v20.html + */ + +package org.junit.jupiter.engine.descriptor; + +import org.junit.platform.commons.util.Preconditions; +import org.junit.platform.commons.util.ReflectionUtils; +import org.junit.platform.engine.support.descriptor.MethodSource; + +import java.net.URI; +import java.util.Optional; +import java.util.function.Supplier; + +/** + * @since 5.5 + */ +class MethodSourceUtils { + + static final String METHOD_SCHEME = "method"; + + static MethodSource fromUri(URI uri) { + Preconditions.notNull(uri, "URI must not be null"); + Preconditions.condition(METHOD_SCHEME.equals(uri.getScheme()), + () -> "URI [" + uri + "] must have [" + METHOD_SCHEME + "] scheme"); + + Supplier illegalArgumentExceptionSupplier = () -> new IllegalArgumentException("Invalid method URI"); + String schemeSpecificPart = Optional.ofNullable(uri.getSchemeSpecificPart()).orElseThrow(illegalArgumentExceptionSupplier); + String fragment = Optional.ofNullable(uri.getFragment()).orElseThrow(illegalArgumentExceptionSupplier); + + String fullyQualifiedMethodName = schemeSpecificPart + "#" + fragment; + String[] methodSpec = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName); + return MethodSource.from(methodSpec[0], methodSpec[1], methodSpec[2]); + } +} diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java index 61793747a99b..9c8a301cb3f0 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java @@ -11,6 +11,7 @@ package org.junit.jupiter.engine.descriptor; import static org.apiguardian.api.API.Status.INTERNAL; +import static org.junit.jupiter.engine.descriptor.MethodSourceUtils.METHOD_SCHEME; import static org.junit.platform.engine.support.descriptor.ClasspathResourceSource.CLASSPATH_SCHEME; import java.lang.reflect.Method; @@ -165,7 +166,13 @@ static Optional createDynamicDescriptor(JupiterTestDescri */ static TestSource fromUri(URI uri) { Preconditions.notNull(uri, "URI must not be null"); - return CLASSPATH_SCHEME.equals(uri.getScheme()) ? ClasspathResourceSource.from(uri) : UriSource.from(uri); + if (CLASSPATH_SCHEME.equals(uri.getScheme())) { + return ClasspathResourceSource.from(uri); + } else if (METHOD_SCHEME.equals(uri.getScheme())) { + return MethodSourceUtils.fromUri(uri); + } else { + return UriSource.from(uri); + } } /** diff --git a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptorTests.java b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptorTests.java index c48f89ec1e78..27b884f55c00 100644 --- a/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptorTests.java +++ b/junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptorTests.java @@ -37,6 +37,7 @@ import org.junit.platform.engine.support.descriptor.DirectorySource; import org.junit.platform.engine.support.descriptor.FilePosition; import org.junit.platform.engine.support.descriptor.FileSource; +import org.junit.platform.engine.support.descriptor.MethodSource; import org.junit.platform.engine.support.descriptor.UriSource; import org.junit.platform.engine.support.hierarchical.Node; import org.junit.platform.engine.support.hierarchical.OpenTest4JAwareThrowableCollector; @@ -108,6 +109,18 @@ void defaultUriSourceFromUri() { assertThat(source.getUri()).isEqualTo(uri); } + @Test + void methodSourceFromUri() { + URI uri = URI.create("method:org.junit.Foo#bar(java.lang.String,%20java.lang.String[])"); + TestSource testSource = TestFactoryTestDescriptor.fromUri(uri); + + assertThat(testSource).isInstanceOf(MethodSource.class); + assertThat(testSource.getClass().getSimpleName()).isEqualTo("MethodSource"); + MethodSource source = (MethodSource) testSource; + assertThat(source.getClassName()).isEqualTo("org.junit.Foo"); + assertThat(source.getMethodName()).isEqualTo("bar"); + assertThat(source.getMethodParameterTypes()).isEqualTo("java.lang.String, java.lang.String[]"); + } } @Nested From 11851720b93621661c47ca77fc51fe654580818a Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Fri, 24 May 2019 02:51:18 +0200 Subject: [PATCH 2/8] Fix formatting --- .../engine/descriptor/MethodSourceUtils.java | 16 +++++++++------- .../descriptor/TestFactoryTestDescriptor.java | 6 ++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java index 9f7764b0efaa..dd830ca951ab 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java @@ -10,14 +10,14 @@ package org.junit.jupiter.engine.descriptor; -import org.junit.platform.commons.util.Preconditions; -import org.junit.platform.commons.util.ReflectionUtils; -import org.junit.platform.engine.support.descriptor.MethodSource; - import java.net.URI; import java.util.Optional; import java.util.function.Supplier; +import org.junit.platform.commons.util.Preconditions; +import org.junit.platform.commons.util.ReflectionUtils; +import org.junit.platform.engine.support.descriptor.MethodSource; + /** * @since 5.5 */ @@ -28,10 +28,12 @@ class MethodSourceUtils { static MethodSource fromUri(URI uri) { Preconditions.notNull(uri, "URI must not be null"); Preconditions.condition(METHOD_SCHEME.equals(uri.getScheme()), - () -> "URI [" + uri + "] must have [" + METHOD_SCHEME + "] scheme"); + () -> "URI [" + uri + "] must have [" + METHOD_SCHEME + "] scheme"); - Supplier illegalArgumentExceptionSupplier = () -> new IllegalArgumentException("Invalid method URI"); - String schemeSpecificPart = Optional.ofNullable(uri.getSchemeSpecificPart()).orElseThrow(illegalArgumentExceptionSupplier); + Supplier illegalArgumentExceptionSupplier = () -> new IllegalArgumentException( + "Invalid method URI"); + String schemeSpecificPart = Optional.ofNullable(uri.getSchemeSpecificPart()).orElseThrow( + illegalArgumentExceptionSupplier); String fragment = Optional.ofNullable(uri.getFragment()).orElseThrow(illegalArgumentExceptionSupplier); String fullyQualifiedMethodName = schemeSpecificPart + "#" + fragment; diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java index 9c8a301cb3f0..76e2dcf14582 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java @@ -168,9 +168,11 @@ static TestSource fromUri(URI uri) { Preconditions.notNull(uri, "URI must not be null"); if (CLASSPATH_SCHEME.equals(uri.getScheme())) { return ClasspathResourceSource.from(uri); - } else if (METHOD_SCHEME.equals(uri.getScheme())) { + } + else if (METHOD_SCHEME.equals(uri.getScheme())) { return MethodSourceUtils.fromUri(uri); - } else { + } + else { return UriSource.from(uri); } } From 3f75273577b87baff604750542f5b773ada88d87 Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Fri, 24 May 2019 13:58:00 +0200 Subject: [PATCH 3/8] address review comments --- .../engine/descriptor/MethodSourceUtils.java | 14 ++++++-------- .../descriptor/TestFactoryTestDescriptor.java | 4 +--- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java index dd830ca951ab..17ebffcbc14b 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java @@ -11,8 +11,6 @@ package org.junit.jupiter.engine.descriptor; import java.net.URI; -import java.util.Optional; -import java.util.function.Supplier; import org.junit.platform.commons.util.Preconditions; import org.junit.platform.commons.util.ReflectionUtils; @@ -29,12 +27,12 @@ static MethodSource fromUri(URI uri) { Preconditions.notNull(uri, "URI must not be null"); Preconditions.condition(METHOD_SCHEME.equals(uri.getScheme()), () -> "URI [" + uri + "] must have [" + METHOD_SCHEME + "] scheme"); - - Supplier illegalArgumentExceptionSupplier = () -> new IllegalArgumentException( - "Invalid method URI"); - String schemeSpecificPart = Optional.ofNullable(uri.getSchemeSpecificPart()).orElseThrow( - illegalArgumentExceptionSupplier); - String fragment = Optional.ofNullable(uri.getFragment()).orElseThrow(illegalArgumentExceptionSupplier); + String schemeSpecificPart = uri.getSchemeSpecificPart(); + Preconditions.notNull(schemeSpecificPart, + "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported format."); + String fragment = uri.getFragment(); + Preconditions.notNull(fragment, + "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported format."); String fullyQualifiedMethodName = schemeSpecificPart + "#" + fragment; String[] methodSpec = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName); diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java index 76e2dcf14582..53ff0f62e025 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java @@ -172,9 +172,7 @@ static TestSource fromUri(URI uri) { else if (METHOD_SCHEME.equals(uri.getScheme())) { return MethodSourceUtils.fromUri(uri); } - else { - return UriSource.from(uri); - } + return UriSource.from(uri); } /** From 4f273baee50e20619270de3f5973b5d6f881929f Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Mon, 27 May 2019 11:59:24 +0200 Subject: [PATCH 4/8] Add javadoc --- .../engine/descriptor/MethodSourceUtils.java | 27 ++++++++++++++++--- .../descriptor/TestFactoryTestDescriptor.java | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java index 17ebffcbc14b..590045d85c71 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java @@ -12,8 +12,10 @@ import java.net.URI; +import org.junit.platform.commons.PreconditionViolationException; import org.junit.platform.commons.util.Preconditions; import org.junit.platform.commons.util.ReflectionUtils; +import org.junit.platform.engine.discovery.DiscoverySelectors; import org.junit.platform.engine.support.descriptor.MethodSource; /** @@ -23,16 +25,35 @@ class MethodSourceUtils { static final String METHOD_SCHEME = "method"; - static MethodSource fromUri(URI uri) { + /** + * Create a new {@code MethodSource} from the supplied {@link URI}. + * + *

The supplied {@link URI} should be of the form {@code method:} where FQMN is the fully qualified method name + * see {@link DiscoverySelectors#selectMethod(String)} for the supported formats. + * + *

The {@link URI#getSchemeSpecificPart() schemeSpecificPart} component of the {@code URI} + * will be used as fully qualified class name. The {@linkplain URI#getFragment() fragment} component of the {@code URI} + * will be used to retrieve the method name and method parameter types. + * + * @param uri the {@code URI} for the method; never {@code null} + * @return a new {@code MethodSource}; never {@code null} + * @throws PreconditionViolationException if the supplied {@code URI} is + * {@code null} or if the scheme of the supplied {@code URI} is not equal to the {@link #METHOD_SCHEME} + * or if {@code URI#getSchemeSpecificPart()} is {@code null} or if {@code URI#getFragment()} is {@code null} + * @since 5.5 + * @see #METHOD_SCHEME + * @see DiscoverySelectors#selectMethod(String) + */ + static MethodSource from(URI uri) { Preconditions.notNull(uri, "URI must not be null"); Preconditions.condition(METHOD_SCHEME.equals(uri.getScheme()), () -> "URI [" + uri + "] must have [" + METHOD_SCHEME + "] scheme"); String schemeSpecificPart = uri.getSchemeSpecificPart(); Preconditions.notNull(schemeSpecificPart, - "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported format."); + "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported formats."); String fragment = uri.getFragment(); Preconditions.notNull(fragment, - "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported format."); + "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported formats."); String fullyQualifiedMethodName = schemeSpecificPart + "#" + fragment; String[] methodSpec = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName); diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java index 53ff0f62e025..5a2691cd5a93 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java @@ -170,7 +170,7 @@ static TestSource fromUri(URI uri) { return ClasspathResourceSource.from(uri); } else if (METHOD_SCHEME.equals(uri.getScheme())) { - return MethodSourceUtils.fromUri(uri); + return MethodSourceUtils.from(uri); } return UriSource.from(uri); } From 0466734b327ed03e9480e36ef83718de3e212053 Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Mon, 27 May 2019 12:15:49 +0200 Subject: [PATCH 5/8] Improve javaodc and add API documentation --- ...ethodSourceUtils.java => MethodSourceSupport.java} | 11 ++++++++++- .../engine/descriptor/TestFactoryTestDescriptor.java | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) rename junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/{MethodSourceUtils.java => MethodSourceSupport.java} (89%) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java similarity index 89% rename from junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java rename to junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java index 590045d85c71..240141a2101e 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceUtils.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java @@ -12,16 +12,25 @@ import java.net.URI; +import org.apiguardian.api.API; import org.junit.platform.commons.PreconditionViolationException; import org.junit.platform.commons.util.Preconditions; import org.junit.platform.commons.util.ReflectionUtils; import org.junit.platform.engine.discovery.DiscoverySelectors; +import org.junit.platform.engine.discovery.MethodSelector; import org.junit.platform.engine.support.descriptor.MethodSource; +import static org.apiguardian.api.API.Status.INTERNAL; + /** + * Jupiter internal support for creating {@link MethodSource} from {@link URI}. + * * @since 5.5 + * @see MethodSource + * @see MethodSelector */ -class MethodSourceUtils { +@API(status = INTERNAL, since = "5.5") +class MethodSourceSupport { static final String METHOD_SCHEME = "method"; diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java index 5a2691cd5a93..86ebb06591dd 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java @@ -11,7 +11,7 @@ package org.junit.jupiter.engine.descriptor; import static org.apiguardian.api.API.Status.INTERNAL; -import static org.junit.jupiter.engine.descriptor.MethodSourceUtils.METHOD_SCHEME; +import static org.junit.jupiter.engine.descriptor.MethodSourceSupport.METHOD_SCHEME; import static org.junit.platform.engine.support.descriptor.ClasspathResourceSource.CLASSPATH_SCHEME; import java.lang.reflect.Method; @@ -170,7 +170,7 @@ static TestSource fromUri(URI uri) { return ClasspathResourceSource.from(uri); } else if (METHOD_SCHEME.equals(uri.getScheme())) { - return MethodSourceUtils.from(uri); + return MethodSourceSupport.from(uri); } return UriSource.from(uri); } From 7c64560d1cb26c0112fc232cac6089114ee30a3a Mon Sep 17 00:00:00 2001 From: Issam El-atif Date: Mon, 27 May 2019 12:31:43 +0200 Subject: [PATCH 6/8] Fix formatting --- .../junit/jupiter/engine/descriptor/MethodSourceSupport.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java index 240141a2101e..c18f60655a95 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java @@ -10,6 +10,8 @@ package org.junit.jupiter.engine.descriptor; +import static org.apiguardian.api.API.Status.INTERNAL; + import java.net.URI; import org.apiguardian.api.API; @@ -20,8 +22,6 @@ import org.junit.platform.engine.discovery.MethodSelector; import org.junit.platform.engine.support.descriptor.MethodSource; -import static org.apiguardian.api.API.Status.INTERNAL; - /** * Jupiter internal support for creating {@link MethodSource} from {@link URI}. * From e7061aafea7d91044541c6f073f68361d3a58d7a Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Tue, 28 May 2019 20:33:11 +0200 Subject: [PATCH 7/8] Document #1850 in release notes --- .../docs/asciidoc/release-notes/release-notes-5.5.0-RC1.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/documentation/src/docs/asciidoc/release-notes/release-notes-5.5.0-RC1.adoc b/documentation/src/docs/asciidoc/release-notes/release-notes-5.5.0-RC1.adoc index c8719d826176..b6e19fd7fdd3 100644 --- a/documentation/src/docs/asciidoc/release-notes/release-notes-5.5.0-RC1.adoc +++ b/documentation/src/docs/asciidoc/release-notes/release-notes-5.5.0-RC1.adoc @@ -79,6 +79,8 @@ on GitHub. * New `InvocationInterceptor` extension API (see <<../user-guide/index.adoc#extensions-intercepting-invocations, User Guide>> for details). +* Added support for method URIs, e.g. `method:org.junit.Foo#bar()`, to `DynamicContainer` + and `DynamicTest` factory methods. [[release-notes-5.5.0-RC1-junit-vintage]] From 1d0d14087ad83bad0d800b8967c41a0f9d5ee710 Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Tue, 28 May 2019 20:44:39 +0200 Subject: [PATCH 8/8] Polishing --- .../descriptor/MethodSourceSupport.java | 32 ++++++++----------- .../descriptor/TestFactoryTestDescriptor.java | 2 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java index c18f60655a95..1f55d68352ce 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/MethodSourceSupport.java @@ -10,12 +10,8 @@ package org.junit.jupiter.engine.descriptor; -import static org.apiguardian.api.API.Status.INTERNAL; - import java.net.URI; -import org.apiguardian.api.API; -import org.junit.platform.commons.PreconditionViolationException; import org.junit.platform.commons.util.Preconditions; import org.junit.platform.commons.util.ReflectionUtils; import org.junit.platform.engine.discovery.DiscoverySelectors; @@ -29,7 +25,6 @@ * @see MethodSource * @see MethodSelector */ -@API(status = INTERNAL, since = "5.5") class MethodSourceSupport { static final String METHOD_SCHEME = "method"; @@ -37,18 +32,17 @@ class MethodSourceSupport { /** * Create a new {@code MethodSource} from the supplied {@link URI}. * - *

The supplied {@link URI} should be of the form {@code method:} where FQMN is the fully qualified method name - * see {@link DiscoverySelectors#selectMethod(String)} for the supported formats. + *

The supplied {@link URI} should be of the form {@code method:} + * where FQMN is the fully qualified method name. See + * {@link DiscoverySelectors#selectMethod(String)} for the supported formats. * - *

The {@link URI#getSchemeSpecificPart() schemeSpecificPart} component of the {@code URI} - * will be used as fully qualified class name. The {@linkplain URI#getFragment() fragment} component of the {@code URI} + *

The {@link URI#getSchemeSpecificPart() scheme-specific part} + * component of the {@code URI} will be used as fully qualified class name. + * The {@linkplain URI#getFragment() fragment} component of the {@code URI} * will be used to retrieve the method name and method parameter types. * * @param uri the {@code URI} for the method; never {@code null} * @return a new {@code MethodSource}; never {@code null} - * @throws PreconditionViolationException if the supplied {@code URI} is - * {@code null} or if the scheme of the supplied {@code URI} is not equal to the {@link #METHOD_SCHEME} - * or if {@code URI#getSchemeSpecificPart()} is {@code null} or if {@code URI#getFragment()} is {@code null} * @since 5.5 * @see #METHOD_SCHEME * @see DiscoverySelectors#selectMethod(String) @@ -57,12 +51,14 @@ static MethodSource from(URI uri) { Preconditions.notNull(uri, "URI must not be null"); Preconditions.condition(METHOD_SCHEME.equals(uri.getScheme()), () -> "URI [" + uri + "] must have [" + METHOD_SCHEME + "] scheme"); - String schemeSpecificPart = uri.getSchemeSpecificPart(); - Preconditions.notNull(schemeSpecificPart, - "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported formats."); - String fragment = uri.getFragment(); - Preconditions.notNull(fragment, - "Invalid method URI. Consult the Javadoc for org.junit.platform.engine.discovery.DiscoverySelectors.selectMethod(String) for details on the supported formats."); + String schemeSpecificPart = Preconditions.notNull(uri.getSchemeSpecificPart(), + () -> "Invalid method URI (scheme-specific part must not be null). Please consult the Javadoc of " + + DiscoverySelectors.class.getName() + + "#selectMethod(String) for details on the supported formats."); + String fragment = Preconditions.notNull(uri.getFragment(), + () -> "Invalid method URI (fragment must not be null). Please consult the Javadoc of " + + DiscoverySelectors.class.getName() + + "#selectMethod(String) for details on the supported formats."); String fullyQualifiedMethodName = schemeSpecificPart + "#" + fragment; String[] methodSpec = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName); diff --git a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java index 86ebb06591dd..b29dcaf8715d 100644 --- a/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java +++ b/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/TestFactoryTestDescriptor.java @@ -169,7 +169,7 @@ static TestSource fromUri(URI uri) { if (CLASSPATH_SCHEME.equals(uri.getScheme())) { return ClasspathResourceSource.from(uri); } - else if (METHOD_SCHEME.equals(uri.getScheme())) { + if (METHOD_SCHEME.equals(uri.getScheme())) { return MethodSourceSupport.from(uri); } return UriSource.from(uri);