Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ to start reporting discovery issues.
failures.
* Add support for Kotlin `Sequence` to `@MethodSource`, `@FieldSource`, and
`@TestFactory`.
* Allow publishing files to an existing directory via `TestReporter` and
`ExtensionContext`, for example, when re-running a test class.


[[release-notes-5.13.0-junit-vintage]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ default void publishReportEntry(String value) {
* and attach it to the current test or container.
*
* <p>The directory will be resolved and created in the report output directory
* prior to invoking the supplied action.
* prior to invoking the supplied action, if it doesn't already exist.
*
* @param name the name of the directory to be attached; never {@code null}
* or blank and must not contain any path separators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ public void publishDirectory(String name, ThrowingConsumer<Path> action) {
Preconditions.notNull(action, "action must not be null");

ThrowingConsumer<Path> enhancedAction = path -> {
Files.createDirectory(path);
if (!Files.isDirectory(path)) {
Files.createDirectory(path);
}
action.accept(path);
};
publishFileEntry(name, enhancedAction, file -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,19 @@ void failsWhenAttemptingToPublishRegularFilesAsDirectories(@TempDir Path tempDir
"Published path must be a directory: " + tempDir.resolve("OuterClass").resolve("test"));
}

@Test
void allowsPublishingToTheSameDirectoryTwice(@TempDir Path tempDir) {
var extensionContext = createExtensionContextForFilePublishing(tempDir);

extensionContext.publishDirectory("test",
dir -> Files.writeString(dir.resolve("nested1.txt"), "Nested content 1"));
extensionContext.publishDirectory("test",
dir -> Files.writeString(dir.resolve("nested2.txt"), "Nested content 2"));

assertThat(tempDir.resolve("OuterClass/test/nested1.txt")).hasContent("Nested content 1");
assertThat(tempDir.resolve("OuterClass/test/nested2.txt")).hasContent("Nested content 2");
}

private ExtensionContext createExtensionContextForFilePublishing(Path tempDir) {
return createExtensionContextForFilePublishing(tempDir, mock(EngineExecutionListener.class),
outerClassDescriptor(null));
Expand Down