27
27
import java .util .logging .Level ;
28
28
import java .util .logging .LogRecord ;
29
29
30
- import org .junit .jupiter .api .AfterAll ;
30
+ import org .junit .jupiter .api .AfterEach ;
31
31
import org .junit .jupiter .api .MethodOrderer ;
32
32
import org .junit .jupiter .api .Nested ;
33
33
import org .junit .jupiter .api .Order ;
@@ -60,6 +60,7 @@ class TempDirFieldTests {
60
60
private static Path alwaysFieldDir ;
61
61
private static Path onSuccessFailingFieldDir ;
62
62
private static Path onSuccessPassingFieldDir ;
63
+ private static Path onSuccessPassingParameterDir ;
63
64
64
65
/**
65
66
* Ensure the cleanup mode defaults to ALWAYS for fields.
@@ -152,6 +153,14 @@ void cleanupModeOnSuccessFailingField() {
152
153
assertThat (onSuccessFailingFieldDir ).exists ();
153
154
}
154
155
156
+ @ Test
157
+ void cleanupModeOnSuccessFailingThenPassingField () {
158
+ executeTests (selectClass (OnSuccessFailingFieldCase .class ), selectClass (OnSuccessPassingFieldCase .class ));
159
+
160
+ assertThat (onSuccessFailingFieldDir ).exists ();
161
+ assertThat (onSuccessPassingFieldDir ).doesNotExist ();
162
+ }
163
+
155
164
/**
156
165
* Ensure that ON_SUCCESS cleanup modes are obeyed for static fields when tests are failing.
157
166
* <p/>
@@ -174,21 +183,20 @@ void cleanupModeOnSuccessFailingStaticField() {
174
183
*/
175
184
@ Test
176
185
void cleanupModeOnSuccessFailingStaticFieldWithNesting () {
177
- LauncherDiscoveryRequest request = request ()//
178
- .selectors (selectClass (OnSuccessFailingStaticFieldWithNestingCase .class ))//
179
- .build ();
180
- executeTests (request );
186
+ executeTestsForClass (OnSuccessFailingStaticFieldWithNestingCase .class );
181
187
182
188
assertThat (onSuccessFailingFieldDir ).exists ();
189
+ assertThat (onSuccessPassingParameterDir ).doesNotExist ();
183
190
}
184
191
185
- @ AfterAll
186
- static void afterAll () throws IOException {
192
+ @ AfterEach
193
+ void deleteTempDirs () throws IOException {
187
194
deleteIfNotNullAndExists (defaultFieldDir );
188
195
deleteIfNotNullAndExists (neverFieldDir );
189
196
deleteIfNotNullAndExists (alwaysFieldDir );
190
197
deleteIfNotNullAndExists (onSuccessFailingFieldDir );
191
198
deleteIfNotNullAndExists (onSuccessPassingFieldDir );
199
+ deleteIfNotNullAndExists (onSuccessPassingParameterDir );
192
200
}
193
201
194
202
static void deleteIfNotNullAndExists (Path dir ) throws IOException {
@@ -286,13 +294,21 @@ static class OnSuccessFailingStaticFieldWithNestingCase {
286
294
static Path onSuccessFailingFieldDir ;
287
295
288
296
@ Nested
297
+ @ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
289
298
class NestedTestCase {
290
299
291
300
@ Test
292
- void test () {
301
+ @ Order (1 )
302
+ void failingTest () {
293
303
TempDirFieldTests .onSuccessFailingFieldDir = onSuccessFailingFieldDir ;
294
304
fail ();
295
305
}
306
+
307
+ @ Test
308
+ @ Order (2 )
309
+ void passingTest (@ TempDir (cleanup = ON_SUCCESS ) Path tempDir ) {
310
+ TempDirFieldTests .onSuccessPassingParameterDir = tempDir ;
311
+ }
296
312
}
297
313
}
298
314
@@ -400,8 +416,16 @@ void cleanupModeOnSuccessFailingParameter() {
400
416
assertThat (onSuccessFailingParameterDir ).exists ();
401
417
}
402
418
403
- @ AfterAll
404
- static void afterAll () throws IOException {
419
+ @ Test
420
+ void cleanupModeOnSuccessFailingThenPassingParameter () {
421
+ executeTestsForClass (OnSuccessFailingThenPassingParameterCase .class );
422
+
423
+ assertThat (onSuccessFailingParameterDir ).exists ();
424
+ assertThat (onSuccessPassingParameterDir ).doesNotExist ();
425
+ }
426
+
427
+ @ AfterEach
428
+ void deleteTempDirs () throws IOException {
405
429
TempDirFieldTests .deleteIfNotNullAndExists (defaultParameterDir );
406
430
TempDirFieldTests .deleteIfNotNullAndExists (neverParameterDir );
407
431
TempDirFieldTests .deleteIfNotNullAndExists (alwaysParameterDir );
@@ -457,6 +481,24 @@ void testOnSuccessFailingParameter(@TempDir(cleanup = ON_SUCCESS) Path onSuccess
457
481
}
458
482
}
459
483
484
+ @ SuppressWarnings ({ "JUnitMalformedDeclaration" , "NewClassNamingConvention" })
485
+ @ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
486
+ static class OnSuccessFailingThenPassingParameterCase {
487
+
488
+ @ Test
489
+ @ Order (1 )
490
+ void testOnSuccessFailingParameter (@ TempDir (cleanup = ON_SUCCESS ) Path onSuccessFailingParameterDir ) {
491
+ TempDirParameterTests .onSuccessFailingParameterDir = onSuccessFailingParameterDir ;
492
+ fail ();
493
+ }
494
+
495
+ @ Test
496
+ @ Order (2 )
497
+ void testOnSuccessPassingParameter (@ TempDir (cleanup = ON_SUCCESS ) Path onSuccessPassingParameterDir ) {
498
+ TempDirParameterTests .onSuccessPassingParameterDir = onSuccessPassingParameterDir ;
499
+ }
500
+ }
501
+
460
502
}
461
503
462
504
@ Nested
0 commit comments