32
32
import org .junit .Before ;
33
33
import org .junit .Test ;
34
34
import org .junit .jupiter .api .DisplayName ;
35
+ import org .junit .jupiter .api .DisplayNameGenerator ;
36
+ import org .junit .jupiter .engine .config .DefaultJupiterConfiguration ;
37
+ import org .junit .jupiter .engine .config .JupiterConfiguration ;
35
38
import org .junit .jupiter .engine .descriptor .ClassTestDescriptor ;
36
39
import org .junit .jupiter .engine .descriptor .TestMethodTestDescriptor ;
37
40
import org .junit .jupiter .engine .descriptor .TestTemplateTestDescriptor ;
@@ -89,15 +92,15 @@ public class RunListenerAdapterTest {
89
92
public void setUp () {
90
93
listener = mock (TestReportListener .class );
91
94
adapter = new RunListenerAdapter (listener );
92
- adapter .testPlanExecutionStarted (TestPlan .from (emptyList ()));
95
+ adapter .testPlanExecutionStarted (TestPlan .from (emptyList (), CONFIG_PARAMS ));
93
96
adapter .setRunMode (NORMAL_RUN );
94
97
}
95
98
96
99
@ Test
97
100
public void notifiedWithCorrectNamesWhenMethodExecutionStarted () throws Exception {
98
101
ArgumentCaptor <ReportEntry > entryCaptor = ArgumentCaptor .forClass (ReportEntry .class );
99
102
100
- TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )));
103
+ TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )), CONFIG_PARAMS );
101
104
adapter .testPlanExecutionStarted (testPlan );
102
105
103
106
TestIdentifier methodIdentifier =
@@ -116,7 +119,7 @@ public void notifiedWithCorrectNamesWhenMethodExecutionStarted() throws Exceptio
116
119
public void notifiedWithCompatibleNameForMethodWithArguments () throws Exception {
117
120
ArgumentCaptor <ReportEntry > entryCaptor = ArgumentCaptor .forClass (ReportEntry .class );
118
121
119
- TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )));
122
+ TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )), CONFIG_PARAMS );
120
123
adapter .testPlanExecutionStarted (testPlan );
121
124
122
125
TestIdentifier methodIdentifier =
@@ -140,7 +143,7 @@ public void notifiedEagerlyForTestSetWhenClassExecutionStarted() throws Exceptio
140
143
engine .addChild (parent );
141
144
TestDescriptor child = newMethodDescriptor ();
142
145
parent .addChild (child );
143
- TestPlan plan = TestPlan .from (singletonList (engine ));
146
+ TestPlan plan = TestPlan .from (singletonList (engine ), CONFIG_PARAMS );
144
147
145
148
String className = MyTestClass .class .getName ();
146
149
@@ -196,10 +199,11 @@ public void displayNamesInClassAndMethods() throws Exception {
196
199
197
200
UniqueId id2 = parent .getUniqueId ().append (MyTestClass .class .getName (), MY_TEST_METHOD_NAME );
198
201
Method m2 = MyTestClass .class .getDeclaredMethod (MY_TEST_METHOD_NAME , String .class );
199
- TestDescriptor child2 = new TestMethodTestDescriptor (id2 , MyTestClass .class , m2 );
202
+ TestDescriptor child2 = new TestMethodTestDescriptor (
203
+ id2 , MyTestClass .class , m2 , new DefaultJupiterConfiguration (CONFIG_PARAMS ));
200
204
parent .addChild (child2 );
201
205
202
- TestPlan plan = TestPlan .from (singletonList (engine ));
206
+ TestPlan plan = TestPlan .from (singletonList (engine ), CONFIG_PARAMS );
203
207
204
208
InOrder inOrder = inOrder (listener );
205
209
@@ -291,7 +295,7 @@ public Type getType() {
291
295
return TEST ;
292
296
}
293
297
};
294
- TestPlan plan = TestPlan .from (singletonList (engine ));
298
+ TestPlan plan = TestPlan .from (singletonList (engine ), CONFIG_PARAMS );
295
299
296
300
adapter .testPlanExecutionStarted (plan );
297
301
assertThat ((TestPlan ) getInternalState (adapter , "testPlan" )).isSameAs (plan );
@@ -343,7 +347,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionSkipped() throws Exception
343
347
TestDescriptor method2 = newMethodDescriptor ();
344
348
classTestDescriptor .addChild (method2 );
345
349
engineDescriptor .addChild (classTestDescriptor );
346
- TestPlan testPlan = TestPlan .from (singletonList (engineDescriptor ));
350
+ TestPlan testPlan = TestPlan .from (singletonList (engineDescriptor ), CONFIG_PARAMS );
347
351
adapter .testPlanExecutionStarted (testPlan );
348
352
349
353
TestIdentifier classIdentifier =
@@ -414,7 +418,7 @@ public void notifiedWhenMethodExecutionFailedWithError() throws Exception {
414
418
@ Test
415
419
public void notifiedWithCorrectNamesWhenClassExecutionFailed () {
416
420
ArgumentCaptor <ReportEntry > entryCaptor = ArgumentCaptor .forClass (ReportEntry .class );
417
- TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )));
421
+ TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )), CONFIG_PARAMS );
418
422
adapter .testPlanExecutionStarted (testPlan );
419
423
420
424
adapter .executionFinished (
@@ -432,7 +436,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionFailed() {
432
436
@ Test
433
437
public void notifiedWithCorrectNamesWhenClassExecutionErrored () {
434
438
ArgumentCaptor <ReportEntry > entryCaptor = ArgumentCaptor .forClass (ReportEntry .class );
435
- TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )));
439
+ TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )), CONFIG_PARAMS );
436
440
adapter .testPlanExecutionStarted (testPlan );
437
441
438
442
adapter .executionFinished (
@@ -450,7 +454,7 @@ public void notifiedWithCorrectNamesWhenClassExecutionErrored() {
450
454
@ Test
451
455
public void notifiedWithCorrectNamesWhenContainerFailed () throws Exception {
452
456
ArgumentCaptor <ReportEntry > entryCaptor = ArgumentCaptor .forClass (ReportEntry .class );
453
- TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )));
457
+ TestPlan testPlan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )), CONFIG_PARAMS );
454
458
adapter .testPlanExecutionStarted (testPlan );
455
459
456
460
adapter .executionFinished (newContainerIdentifier (), failed (new RuntimeException ()));
@@ -475,7 +479,7 @@ public void notifiedForTestSetWhenClassExecutionSucceeded() {
475
479
EngineDescriptor engineDescriptor = newEngineDescriptor ();
476
480
TestDescriptor classDescriptor = newClassDescriptor ();
477
481
engineDescriptor .addChild (classDescriptor );
478
- adapter .testPlanExecutionStarted (TestPlan .from (singleton (engineDescriptor )));
482
+ adapter .testPlanExecutionStarted (TestPlan .from (singleton (engineDescriptor ), CONFIG_PARAMS ));
479
483
adapter .executionStarted (TestIdentifier .from (classDescriptor ));
480
484
481
485
adapter .executionFinished (TestIdentifier .from (classDescriptor ), successful ());
@@ -505,7 +509,7 @@ public void notifiedForTestSetWhenClassExecutionSucceeded() {
505
509
@ Test
506
510
public void notifiedWithParentDisplayNameWhenTestClassUnknown () {
507
511
// Set up a test plan
508
- TestPlan plan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )));
512
+ TestPlan plan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Luke's Plan" )), CONFIG_PARAMS );
509
513
adapter .testPlanExecutionStarted (plan );
510
514
511
515
// Use the test plan to set up child with parent.
@@ -525,7 +529,7 @@ public void notifiedWithParentDisplayNameWhenTestClassUnknown() {
525
529
526
530
@ Test
527
531
public void stackTraceWriterPresentWhenParentHasSource () {
528
- TestPlan plan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Some Plan" )));
532
+ TestPlan plan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Some Plan" )), CONFIG_PARAMS );
529
533
adapter .testPlanExecutionStarted (plan );
530
534
531
535
TestIdentifier child =
@@ -538,7 +542,7 @@ public void stackTraceWriterPresentWhenParentHasSource() {
538
542
539
543
@ Test
540
544
public void stackTraceWriterDefaultsToTestClass () {
541
- TestPlan plan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Some Plan" )));
545
+ TestPlan plan = TestPlan .from (singletonList (new EngineDescriptor (newId (), "Some Plan" )), CONFIG_PARAMS );
542
546
adapter .testPlanExecutionStarted (plan );
543
547
544
548
TestIdentifier child = newSourcelessChildIdentifierWithParent (plan , "Parent" , null );
@@ -589,24 +593,29 @@ private static TestDescriptor newMethodDescriptor(Class<?>... parameterTypes) th
589
593
return new TestMethodTestDescriptor (
590
594
UniqueId .forEngine ("method" ),
591
595
MyTestClass .class ,
592
- MyTestClass .class .getDeclaredMethod (MY_TEST_METHOD_NAME , parameterTypes ));
596
+ MyTestClass .class .getDeclaredMethod (MY_TEST_METHOD_NAME , parameterTypes ),
597
+ new DefaultJupiterConfiguration (CONFIG_PARAMS ));
593
598
}
594
599
595
600
private static TestIdentifier newClassIdentifier () {
596
601
return TestIdentifier .from (newClassDescriptor ());
597
602
}
598
603
599
604
private static TestDescriptor newClassDescriptor (String displayName ) {
605
+ JupiterConfiguration jupiterConfiguration = mock (JupiterConfiguration .class );
606
+ DisplayNameGenerator displayNameGenerator = mock (DisplayNameGenerator .class );
607
+ when (displayNameGenerator .generateDisplayNameForClass (MyTestClass .class ))
608
+ .thenReturn (displayName );
609
+ when (jupiterConfiguration .getDefaultDisplayNameGenerator ()).thenReturn (displayNameGenerator );
600
610
return new ClassTestDescriptor (
601
- UniqueId .root ("class" , MyTestClass .class .getName ()),
602
- c -> displayName ,
603
- MyTestClass .class ,
604
- CONFIG_PARAMS ) {};
611
+ UniqueId .root ("class" , MyTestClass .class .getName ()), MyTestClass .class , jupiterConfiguration ) {};
605
612
}
606
613
607
614
private static TestDescriptor newClassDescriptor () {
608
615
return new ClassTestDescriptor (
609
- UniqueId .root ("class" , MyTestClass .class .getName ()), MyTestClass .class , CONFIG_PARAMS );
616
+ UniqueId .root ("class" , MyTestClass .class .getName ()),
617
+ MyTestClass .class ,
618
+ new DefaultJupiterConfiguration (CONFIG_PARAMS ));
610
619
}
611
620
612
621
private static TestIdentifier newSourcelessChildIdentifierWithParent (
@@ -631,8 +640,8 @@ private static TestIdentifier newSourcelessChildIdentifierWithParent(
631
640
when (child .getParent ()).thenReturn (Optional .of (parent ));
632
641
TestIdentifier childId = TestIdentifier .from (child );
633
642
634
- testPlan .add (childId );
635
- testPlan .add (parentId );
643
+ testPlan .addInternal (childId );
644
+ testPlan .addInternal (parentId );
636
645
637
646
return childId ;
638
647
}
@@ -641,7 +650,8 @@ private static TestIdentifier newContainerIdentifier() throws Exception {
641
650
return TestIdentifier .from (new TestTemplateTestDescriptor (
642
651
UniqueId .forEngine ("method" ),
643
652
MyTestClass .class ,
644
- MyTestClass .class .getDeclaredMethod (MY_TEST_METHOD_NAME )));
653
+ MyTestClass .class .getDeclaredMethod (MY_TEST_METHOD_NAME ),
654
+ new DefaultJupiterConfiguration (CONFIG_PARAMS )));
645
655
}
646
656
647
657
private static TestIdentifier newEngineIdentifier () {
@@ -660,15 +670,15 @@ private static TestIdentifier identifiersAsParentOnTestPlan(
660
670
TestIdentifier parentIdentifier = TestIdentifier .from (parent );
661
671
TestIdentifier childIdentifier = TestIdentifier .from (child );
662
672
663
- plan .add (parentIdentifier );
664
- plan .add (childIdentifier );
673
+ plan .addInternal (parentIdentifier );
674
+ plan .addInternal (childIdentifier );
665
675
666
676
return childIdentifier ;
667
677
}
668
678
669
679
private static TestIdentifier identifiersAsParentOnTestPlan (TestPlan plan , TestDescriptor root ) {
670
680
TestIdentifier rootIdentifier = TestIdentifier .from (root );
671
- plan .add (rootIdentifier );
681
+ plan .addInternal (rootIdentifier );
672
682
return rootIdentifier ;
673
683
}
674
684
0 commit comments