Skip to content

Commit e205ccd

Browse files
committed
Polish contribution
See #3311, #3313
1 parent 6ae599b commit e205ccd

File tree

5 files changed

+30
-24
lines changed

5 files changed

+30
-24
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.10.0-RC1.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ JUnit repository on GitHub.
2424
==== New Features and Improvements
2525

2626
* New `@SelectMethod` selector support in the `@Suite` test engine.
27-
* Add `@SelectMethod` selector support to `@Suite` test engine
28-
* `@TempDir` can now be used in meta-annotations
2927

3028

3129
[[release-notes-5.10.0-RC1-junit-jupiter]]
@@ -41,6 +39,10 @@ JUnit repository on GitHub.
4139

4240
==== New Features and Improvements
4341

42+
* `@TempDir` can now be used as a meta-annotation in order to create custom _composed
43+
annotations_. See the `@JimfsTempDir` example in the
44+
<<../user-guide/index.adoc#writing-tests-built-in-extensions-TempDirectory, User Guide>>
45+
for details.
4446
* Lifecycle and thread-safety semantics are now documented for the `TempDirFactory` SPI.
4547

4648

documentation/src/docs/asciidoc/user-guide/writing-tests.adoc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,8 +2627,8 @@ they are instantiated, but they can assume that their `createTempDirectory(...)`
26272627
thread.
26282628

26292629
The default implementation available in Jupiter delegates the directory creation to
2630-
`java.nio.file.Files::createTempDirectory`, passing `junit` as the prefix string
2631-
to be used in generating the directory's name.
2630+
`java.nio.file.Files::createTempDirectory`, passing `junit` as the prefix string to be
2631+
used in generating the directory's name.
26322632

26332633
The following example defines a factory that uses the test name as the directory name
26342634
prefix instead of the `junit` constant value.
@@ -2640,25 +2640,31 @@ include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_factory_name_p
26402640
----
26412641

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

26452645
[source,java,indent=0]
26462646
.A test class with a temporary directory created with the Jimfs in-memory file system
26472647
----
26482648
include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_factory_jimfs]
26492649
----
26502650

2651-
`@TempDir` can also be used in meta-annotations to reduce repetition.
2651+
`@TempDir` can also be used as a <<writing-tests-meta-annotations, meta-annotation>> to
2652+
reduce repetition. The following code listing shows how to create a custom `@JimfsTempDir`
2653+
annotation that can be used as a drop-in replacement for
2654+
`@TempDir(factory = JimfsTempDirFactory.class)`.
26522655

26532656
[source,java,indent=0]
2654-
.A definition of a meta-annotation using `@TempDir`
2657+
.A custom annotation meta-annotated with `@TempDir`
26552658
----
2656-
include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_meta_annotation]
2659+
include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_composed_annotation]
26572660
----
2661+
2662+
The following example demonstrates how to use the custom `@JimfsTempDir` annotation.
2663+
26582664
[source,java,indent=0]
2659-
.A test class using a meta-annotation
2665+
.A test class using the custom annotation
26602666
----
2661-
include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_meta_annotation_usage]
2667+
include::{testDir}/example/TempDirectoryDemo.java[tags=user_guide_composed_annotation_usage]
26622668
----
26632669

26642670
You can use the `junit.jupiter.tempdir.factory.default`

documentation/src/test/java/example/TempDirectoryDemo.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,16 @@ public void close() throws IOException {
147147
}
148148
// end::user_guide_factory_jimfs[]
149149

150-
// tag::user_guide_meta_annotation[]
150+
// tag::user_guide_composed_annotation[]
151151
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.PARAMETER })
152152
@Retention(RetentionPolicy.RUNTIME)
153153
@TempDir(factory = JimfsTempDirFactory.class)
154154
@interface JimfsTempDir {
155-
156155
}
157-
// end::user_guide_meta_annotation[]
156+
// end::user_guide_composed_annotation[]
158157

159158
static
160-
// tag::user_guide_meta_annotation_usage[]
159+
// tag::user_guide_composed_annotation_usage[]
161160
class JimfsTempDirAnnotationDemo {
162161

163162
@Test
@@ -166,6 +165,6 @@ void test(@JimfsTempDir Path tempDir) {
166165
}
167166

168167
}
169-
// end::user_guide_meta_annotation_usage[]
168+
// end::user_guide_composed_annotation_usage[]
170169

171170
}

junit-jupiter-api/src/main/java/org/junit/jupiter/api/io/TempDir.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
*
9191
* @since 5.4
9292
*/
93-
@Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.ANNOTATION_TYPE })
93+
@Target({ ElementType.ANNOTATION_TYPE, ElementType.FIELD, ElementType.PARAMETER })
9494
@Retention(RetentionPolicy.RUNTIME)
9595
@Documented
9696
@API(status = STABLE, since = "5.10")

junit-jupiter-engine/src/test/java/org/junit/jupiter/engine/extension/TempDirectoryMetaAnnotationTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ class TempDirectoryMetaAnnotationTests extends AbstractJupiterTestEngineTests {
3434

3535
@Test
3636
void annotationOnField() {
37-
executeTestsForClass(AnnotationOnFieldTestCase.class).testEvents().assertStatistics(
38-
stats -> stats.started(1).succeeded(1));
37+
executeTestsForClass(AnnotationOnFieldTestCase.class).testEvents()//
38+
.assertStatistics(stats -> stats.started(1).succeeded(1));
3939
}
4040

4141
@Test
4242
void annotationOnParameter() {
43-
executeTestsForClass(AnnotationOnParameterTestCase.class).testEvents().assertStatistics(
44-
stats -> stats.started(1).succeeded(1));
43+
executeTestsForClass(AnnotationOnParameterTestCase.class).testEvents()//
44+
.assertStatistics(stats -> stats.started(1).succeeded(1));
4545
}
4646

4747
static class AnnotationOnFieldTestCase {
4848

49-
@MetaTempDir
49+
@CustomTempDir
5050
private Path tempDir;
5151

5252
@Test
@@ -59,7 +59,7 @@ void test() {
5959
static class AnnotationOnParameterTestCase {
6060

6161
@Test
62-
void test(@MetaTempDir Path tempDir) {
62+
void test(@CustomTempDir Path tempDir) {
6363
assertTrue(Files.exists(tempDir));
6464
}
6565

@@ -68,8 +68,7 @@ void test(@MetaTempDir Path tempDir) {
6868
@TempDir
6969
@Target({ ElementType.FIELD, ElementType.PARAMETER })
7070
@Retention(RetentionPolicy.RUNTIME)
71-
@interface MetaTempDir {
72-
71+
@interface CustomTempDir {
7372
}
7473

7574
}

0 commit comments

Comments
 (0)