Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen authored and Cody Moore committed Sep 15, 2018
1 parent 11dad09 commit d8226d3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,22 @@ public static DynamicContainer dynamicContainer(String displayName, Stream<? ext

/**
* Factory for creating a new {@code DynamicContainer} for the supplied display
* name, the test source {@link URI}, and stream of dynamic nodes.
* name, custom test source {@link URI}, and stream of dynamic nodes.
*
* <p>The stream of dynamic nodes must not contain {@code null} elements.
*
* @param displayName the display name for the dynamic container; never
* {@code null} or blank
* @param testSourceUri the test source URI for the dynamic test; can be {@code null}
* @param dynamicNodes stream of dynamic nodes to execute;
* never {@code null}
* @param testSourceUri a custom test source URI for the dynamic container;
* may be {@code null} if the framework should generate the test source based
* on the {@code @TestFactory} method
* @param dynamicNodes stream of dynamic nodes to execute; never {@code null}
* @since 5.3
* @see #dynamicContainer(String, Iterable)
*/
public static DynamicContainer dynamicContainer(String displayName, URI testSourceUri,
Stream<? extends DynamicNode> dynamicNodes) {

return new DynamicContainer(displayName, testSourceUri, dynamicNodes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class DynamicNode {

private final String displayName;

/** Custom test source {@link URI} instance associated with this node; potentially {@code null}. */
/** Custom test source {@link URI} associated with this node; potentially {@code null}. */
private final URI testSourceUri;

DynamicNode(String displayName, URI testSourceUri) {
Expand All @@ -50,9 +50,9 @@ public String getDisplayName() {
}

/**
* Get the optional test source {@link URI} of this {@code DynamicNode}.
* Get the custom test source {@link URI} of this {@code DynamicNode}.
*
* @return an {@code Optional} containing the test source {@link URI};
* @return an {@code Optional} containing the custom test source {@link URI};
* never {@code null} but potentially empty
* @since 5.3
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ public static DynamicTest dynamicTest(String displayName, Executable executable)

/**
* Factory for creating a new {@code DynamicTest} for the supplied display
* name, the test source {@link URI}, and executable code block.
* name, custom test source {@link URI}, and executable code block.
*
* @param displayName the display name for the dynamic test; never
* {@code null} or blank
* @param testSourceUri the test source URI for the dynamic test; can be {@code null}
* @param testSourceUri a custom test source URI for the dynamic test; may
* be {@code null} if the framework should generate the test source based on
* the {@code @TestFactory} method
* @param executable the executable code block for the dynamic test;
* never {@code null}
* @since 5.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ private JUnitException invalidReturnTypeException(Throwable cause) {

static Optional<JupiterTestDescriptor> createDynamicDescriptor(JupiterTestDescriptor parent, DynamicNode node,
int index, TestSource defaultTestSource, DynamicDescendantFilter dynamicDescendantFilter) {

UniqueId uniqueId;
Supplier<JupiterTestDescriptor> descriptorCreator;
Optional<TestSource> optionalTestSource = node.getTestSourceUri().map(UriSource::from);
TestSource source = optionalTestSource.orElse(defaultTestSource);
Optional<TestSource> customTestSource = node.getTestSourceUri().map(UriSource::from);
TestSource source = customTestSource.orElse(defaultTestSource);

if (node instanceof DynamicTest) {
DynamicTest test = (DynamicTest) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_TEST_SEGMENT_TYPE, "#" + index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ public static FilePosition from(int line, int column) {
*
* @param query the query string; may be {@code null}
* @return an {@link Optional} containing a {@link FilePosition} with
* the parsed line and column numbers; potentially empty
* the parsed line and column numbers; never {@code null} but potentially
* empty
* @since 1.3
* @see #from(int)
* @see #from(int, int)
*/
public static Optional<FilePosition> fromQuery(String query) {
FilePosition result = null;
Expand All @@ -85,10 +88,10 @@ public static Optional<FilePosition> fromQuery(String query) {
if (data.length == 2) {
String key = data[0];
int value = Integer.valueOf(data[1]);
if (key.equals("line")) {
if ("line".equals(key)) {
line = value;
}
if (key.equals("column")) {
if ("column".equals(key)) {
column = value;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ public interface UriSource extends TestSource {

/**
* Create a new {@code UriSource} using the supplied {@code URI}.
* <p>
* This implementation tries resolve the {@code uri} to local file
* system path-based source first. If that fails for any reason, an
* instance of the default {@code UriSource} implementation storing
* the supplied {@code URI} <em>as-is</em> is returned.
*
* @param uri the URI instance; must not be {@code null}
* @return a uri source instance
* <p>This implementation first attempts to resolve the supplied {@code URI}
* to a path-based {@code UriSource} in the local filesystem. If that fails
* for any reason, an instance of the default {@code UriSource}
* implementation storing the supplied {@code URI} <em>as-is</em> will be
* returned.
*
* @param uri the URI to use as the source; never {@code null}
* @return an appropriate {@code UriSource} for the supplied {@code URI}
* @since 1.3
* @see org.junit.platform.engine.support.descriptor.FileSource
* @see org.junit.platform.engine.support.descriptor.DirectorySource
*/
static UriSource from(final URI uri) {
static UriSource from(URI uri) {
Preconditions.notNull(uri, "URI must not be null");

try {
URI pathBasedUriWithoutQuery = uri;
String query = uri.getQuery();
Expand All @@ -74,7 +76,8 @@ static UriSource from(final URI uri) {
LoggerFactory.getLogger(UriSource.class).debug(e, () -> String.format(
"The supplied URI [%s] is not path-based. Falling back to default UriSource implementation.", uri));
}
// store uri as-is

// Store supplied URI as-is
return new DefaultUriSource(uri);
}

Expand Down

0 comments on commit d8226d3

Please sign in to comment.