1414import static org .junit .jupiter .api .Assertions .assertEquals ;
1515import static org .junit .jupiter .api .Assertions .assertNotEquals ;
1616import static org .junit .jupiter .api .Assertions .assertNotNull ;
17- import static org .junit .jupiter .api .Assertions .assertNull ;
1817import static org .junit .jupiter .api .Assertions .assertSame ;
1918import static org .junit .jupiter .api .Assertions .assertTrue ;
2019import static org .junit .jupiter .api .Assertions .fail ;
@@ -102,21 +101,6 @@ void resolvesSharedTempDirWhenAnnotationIsUsedOnStaticFieldAndBeforeAllMethodPar
102101 assertSharedTempDirForFieldInjection (AnnotationOnStaticFieldAndBeforeAllMethodParameterTestCase .class );
103102 }
104103
105- @ Test
106- @ DisplayName ("when @TempDir is used on instance field and constructor parameter" )
107- @ Order (12 )
108- void resolvesSharedTempDirWhenAnnotationIsUsedOnInstanceFieldAndConstructorParameter () {
109- assertSharedTempDirForFieldInjection (AnnotationOnInstanceFieldAndConstructorParameterTestCase .class );
110- }
111-
112- @ Test
113- @ DisplayName ("when @TempDir is used on instance field and constructor parameter with @TestInstance(PER_CLASS)" )
114- @ Order (13 )
115- void resolvesSharedTempDirWhenAnnotationIsUsedOnInstanceFieldAndConstructorParameterWithTestInstancePerClass () {
116- assertSharedTempDirForFieldInjection (
117- AnnotationOnInstanceFieldAndConstructorParameterWithTestInstancePerClassTestCase .class );
118- }
119-
120104 @ Test
121105 @ DisplayName ("when @TempDir is used on instance field and @BeforeAll method parameter" )
122106 @ Order (14 )
@@ -132,21 +116,6 @@ void resolvesSharedTempDirWhenAnnotationIsUsedOnInstanceFieldAndBeforeAllMethodP
132116 AnnotationOnInstanceFieldAndBeforeAllMethodParameterWithTestInstancePerClassTestCase .class );
133117 }
134118
135- @ Test
136- @ DisplayName ("when @TempDir is used on constructor parameter" )
137- @ Order (21 )
138- void resolvesSharedTempDirWhenAnnotationIsUsedOnConstructorParameter () {
139- assertSharedTempDirForParameterInjection (AnnotationOnConstructorParameterTestCase .class );
140- }
141-
142- @ Test
143- @ DisplayName ("when @TempDir is used on constructor parameter with @TestInstance(PER_CLASS)" )
144- @ Order (22 )
145- void resolvesSharedTempDirWhenAnnotationIsUsedOnConstructorParameterWithTestInstancePerClass () {
146- assertSharedTempDirForParameterInjection (
147- AnnotationOnConstructorParameterWithTestInstancePerClassTestCase .class );
148- }
149-
150119 @ Test
151120 @ DisplayName ("when @TempDir is used on @BeforeAll method parameter" )
152121 @ Order (23 )
@@ -374,6 +343,26 @@ void erroneousParentDirProviderMakesTestFail() {
374343 // @formatter:on
375344 }
376345
346+ @ Test
347+ @ DisplayName ("when @TempDir is used on constructor parameter" )
348+ @ Order (8 )
349+ void resolvesSharedTempDirWhenAnnotationIsUsedOnConstructorParameter () {
350+ var results = executeTestsForClass (AnnotationOnConstructorParameterTestCase .class );
351+
352+ assertSingleFailedTest (results , ParameterResolutionException .class ,
353+ "@TempDir is not supported on constructor parameters. Please use field injection instead." );
354+ }
355+
356+ @ Test
357+ @ DisplayName ("when @TempDir is used on constructor parameter with @TestInstance(PER_CLASS)" )
358+ @ Order (9 )
359+ void resolvesSharedTempDirWhenAnnotationIsUsedOnConstructorParameterWithTestInstancePerClass () {
360+ var results = executeTestsForClass (AnnotationOnConstructorParameterWithTestInstancePerClassTestCase .class );
361+
362+ assertSingleFailedContainer (results , ParameterResolutionException .class ,
363+ "@TempDir is not supported on constructor parameters. Please use field injection instead." );
364+ }
365+
377366 }
378367
379368 private static void assertSingleFailedContainer (EngineExecutionResults results , Class <? extends Throwable > clazz ,
@@ -508,30 +497,6 @@ static void beforeAll(@TempDir Path tempDir) {
508497
509498 }
510499
511- static class AnnotationOnInstanceFieldAndConstructorParameterTestCase
512- extends BaseSharedTempDirFieldInjectionTestCase {
513-
514- AnnotationOnInstanceFieldAndConstructorParameterTestCase (@ TempDir Path tempDir ) {
515- if (BaseSharedTempDirFieldInjectionTestCase .staticTempDir != null ) {
516- assertSame (BaseSharedTempDirFieldInjectionTestCase .staticTempDir , tempDir );
517- }
518- else {
519- BaseSharedTempDirFieldInjectionTestCase .staticTempDir = tempDir ;
520- }
521- assertNull (this .tempDir );
522- assertTrue (Files .exists (tempDir ));
523- }
524- }
525-
526- @ TestInstance (PER_CLASS )
527- static class AnnotationOnInstanceFieldAndConstructorParameterWithTestInstancePerClassTestCase
528- extends AnnotationOnInstanceFieldAndConstructorParameterTestCase {
529-
530- AnnotationOnInstanceFieldAndConstructorParameterWithTestInstancePerClassTestCase (@ TempDir Path tempDir ) {
531- super (tempDir );
532- }
533- }
534-
535500 static class AnnotationOnInstanceFieldAndBeforeAllMethodParameterTestCase
536501 extends BaseSharedTempDirFieldInjectionTestCase {
537502
@@ -608,17 +573,18 @@ static void check(Path tempDir) {
608573
609574 }
610575
611- static class AnnotationOnConstructorParameterTestCase extends BaseSharedTempDirParameterInjectionTestCase {
576+ @ ExtendWith (TempDirectory .class )
577+ static class AnnotationOnConstructorParameterTestCase {
612578
613579 AnnotationOnConstructorParameterTestCase (@ TempDir Path tempDir ) {
614- if (BaseSharedTempDirParameterInjectionTestCase .tempDir != null ) {
615- assertSame (BaseSharedTempDirParameterInjectionTestCase .tempDir , tempDir );
616- }
617- else {
618- BaseSharedTempDirParameterInjectionTestCase .tempDir = tempDir ;
619- }
620- check (tempDir );
580+ // never called
621581 }
582+
583+ @ Test
584+ void test () {
585+ // never called
586+ }
587+
622588 }
623589
624590 @ TestInstance (PER_CLASS )
0 commit comments