Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Jan 29, 2025
1 parent d9848df commit f45b882
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
27 changes: 13 additions & 14 deletions documentation/src/docs/asciidoc/user-guide/writing-tests.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3128,9 +3128,9 @@ include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_field_injectio
----

The `@TempDir` annotation has an optional `cleanup` attribute that can be set to either
`NEVER`, `ON_SUCCESS`, or `ALWAYS`. If the cleanup mode is set to `NEVER`, temporary
directories are not deleted after a test completes. If it is set to `ON_SUCCESS`,
temporary directories are deleted only after a test completed successfully.
`NEVER`, `ON_SUCCESS`, or `ALWAYS`. If the cleanup mode is set to `NEVER`, the temporary
directory will not be deleted after the test completes. If it is set to `ON_SUCCESS`, the
temporary directory will only be deleted after the test if the test completed successfully.

The default cleanup mode is `ALWAYS`. You can use the
`junit.jupiter.tempdir.cleanup.mode.default`
Expand Down Expand Up @@ -3166,7 +3166,7 @@ prefix instead of the `junit` constant value.
include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_factory_name_prefix]
----

It's also possible to use an in-memory file system like `{Jimfs}` for the creation of the
It is also possible to use an in-memory file system like `{Jimfs}` for the creation of the
temporary directory. The following example demonstrates how to achieve that.

[source,java,indent=0]
Expand Down Expand Up @@ -3197,18 +3197,17 @@ include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_composed_annot
Meta-annotations or additional annotations on the field or parameter the `TempDir`
annotation is declared on might expose additional attributes to configure the factory.
Such annotations and related attributes can be accessed via the `AnnotatedElementContext`
parameter of `createTempDirectory`.
parameter of the `createTempDirectory(...)` method.

You can use the `junit.jupiter.tempdir.factory.default`
<<running-tests-config-params, configuration parameter>> to specify the fully qualified
class name of the `TempDirFactory` you would like to use by default. Just like for
factories configured via the `factory` attribute of the `@TempDir` annotation,
the supplied class has to implement the `TempDirFactory` interface. The default factory
will be used for all `@TempDir` annotations unless the `factory` attribute of the
annotation specifies a different factory.
You can use the `junit.jupiter.tempdir.factory.default` <<running-tests-config-params,
configuration parameter>> to specify the fully qualified class name of the
`TempDirFactory` you would like to use by default. Just like for factories configured via
the `factory` attribute of the `@TempDir` annotation, the supplied class has to implement
the `TempDirFactory` interface. The default factory will be used for all `@TempDir`
annotations unless the `factory` attribute of the annotation specifies a different factory.

In summary, the factory for a temporary directory is determined according to the
following precedence rules:
In summary, the factory for a temporary directory is determined according to the following
precedence rules:

1. The `factory` attribute of the `@TempDir` annotation, if present
2. The default `TempDirFactory` configured via the configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@
* cases:
*
* <ul>
* <li>If the field type or parameter type is neither {@link Path} nor
{@link File}.</li>
* <li>If the field type or parameter type is neither {@code Path} nor {@code File}.</li>
* <li>If a field is declared as {@code final}.</li>
* <li>If the temporary directory cannot be created.</li>
* <li>If the field type or parameter type is {@code File} and a custom
* {@linkplain TempDir#factory() factory} is used, which creates a temporary
* {@link TempDir#factory() factory} is used, which creates a temporary
* directory that does not belong to the
* {@linkplain java.nio.file.FileSystems#getDefault() default file system}.
* </li>
Expand Down Expand Up @@ -154,9 +153,10 @@
* <h4>Supported Values</h4>
* <ul>
* <li>{@code per_context}: creates a single temporary directory for the
* entire test class or method, depending on where it's first declared
* entire test class or method, depending on where {@code @TempDir} is first
* declared</li>
* <li>{@code per_declaration}: creates separate temporary directories for
* each declaration site of the {@code @TempDir} annotation.
* each declaration site of the {@code @TempDir} annotation</li>
* </ul>
*
* <p>If not specified, the default is {@code per_declaration}.
Expand Down

0 comments on commit f45b882

Please sign in to comment.