|
17 | 17 | import static org.assertj.core.api.Assertions.fail; |
18 | 18 | import static org.junit.jupiter.api.Assertions.assertAll; |
19 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertNull; |
20 | 21 | import static org.junit.jupiter.api.Assertions.assertThrows; |
21 | 22 | import static org.junit.jupiter.api.Assertions.assertTrue; |
22 | 23 | import static org.junit.jupiter.api.Assumptions.assumeFalse; |
|
36 | 37 | import static org.mockito.Mockito.when; |
37 | 38 |
|
38 | 39 | import java.lang.reflect.Method; |
39 | | -import java.util.ArrayList; |
40 | 40 | import java.util.List; |
41 | 41 |
|
42 | 42 | import org.junit.jupiter.api.Nested; |
|
55 | 55 | import org.junit.platform.engine.discovery.UniqueIdSelector; |
56 | 56 | import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor; |
57 | 57 | import org.junit.platform.engine.support.descriptor.EngineDescriptor; |
| 58 | +import org.junit.platform.engine.support.descriptor.JavaClassSource; |
| 59 | +import org.junit.platform.engine.support.descriptor.JavaMethodSource; |
| 60 | +import org.junit.platform.engine.support.hierarchical.DummyTestDescriptor; |
58 | 61 | import org.junit.platform.engine.support.hierarchical.DummyTestEngine; |
59 | 62 | import org.junit.platform.engine.test.TestDescriptorStub; |
60 | 63 | import org.junit.platform.engine.test.TestEngineStub; |
@@ -388,53 +391,73 @@ void reportsIgnoredEventsForLeavesWhenContainerIsSkipped() throws Exception { |
388 | 391 | class Descriptions { |
389 | 392 |
|
390 | 393 | @Test |
391 | | - void descriptionForJavaMethodSource() throws Exception { |
| 394 | + void descriptionForJavaMethodAndClassSources() throws Exception { |
392 | 395 | DummyTestEngine engine = new DummyTestEngine("dummy"); |
393 | 396 | Method failingTest = getClass().getDeclaredMethod("failingTest"); |
394 | | - engine.addTest(failingTest, () -> { |
395 | | - }); |
| 397 | + DummyTestDescriptor containerDescriptor = engine.addContainer("uniqueContainerName", "containerDisplayName", |
| 398 | + new JavaClassSource(getClass())); |
| 399 | + containerDescriptor.addChild( |
| 400 | + new DummyTestDescriptor(containerDescriptor.getUniqueId().append("test", "failingTest"), |
| 401 | + "testDisplayName", new JavaMethodSource(failingTest), () -> { |
| 402 | + })); |
396 | 403 |
|
397 | 404 | JUnitPlatform platformRunner = new JUnitPlatform(TestClass.class, createLauncher(engine)); |
398 | 405 |
|
399 | | - ArrayList<Description> children = platformRunner.getDescription().getChildren(); |
| 406 | + List<Description> children = platformRunner.getDescription().getChildren(); |
400 | 407 | assertEquals(1, children.size()); |
401 | 408 | Description engineDescription = children.get(0); |
402 | 409 | assertEquals("dummy", engineDescription.getDisplayName()); |
403 | 410 |
|
404 | | - children = engineDescription.getChildren(); |
405 | | - assertEquals(1, children.size()); |
406 | | - Description testDescription = children.get(0); |
| 411 | + Description containerDescription = getOnlyElement(engineDescription.getChildren()); |
| 412 | + Description testDescription = getOnlyElement(containerDescription.getChildren()); |
| 413 | + |
407 | 414 | // @formatter:off |
408 | 415 | assertAll( |
409 | | - () -> assertEquals("dummy", testDescription.getClassName(), "class name"), |
410 | | - () -> assertEquals("failingTest", testDescription.getMethodName(), "method name"), |
411 | | - () -> assertEquals("failingTest(dummy)", testDescription.getDisplayName(), "display name") |
| 416 | + () -> assertEquals("dummy", engineDescription.getDisplayName(), "engine display name"), |
| 417 | + () -> assertEquals("dummy", engineDescription.getClassName(), "engine class name"), |
| 418 | + () -> assertNull(engineDescription.getMethodName(), "engine method name"), |
| 419 | + () -> assertEquals("containerDisplayName", containerDescription.getDisplayName(), "container display name"), |
| 420 | + () -> assertEquals("containerDisplayName", containerDescription.getClassName(), "container class name"), |
| 421 | + () -> assertNull(containerDescription.getMethodName(), "container method name"), |
| 422 | + () -> assertEquals("testDisplayName(containerDisplayName)", testDescription.getDisplayName(), "test display name"), |
| 423 | + () -> assertEquals("containerDisplayName", testDescription.getClassName(), "test class name"), |
| 424 | + () -> assertEquals("testDisplayName", testDescription.getMethodName(), "test method name") |
412 | 425 | ); |
413 | 426 | // @formatter:on |
414 | 427 | } |
415 | 428 |
|
416 | 429 | @Test |
417 | | - void descriptionForJavaMethodSourceUsingTechnicalNames() throws Exception { |
| 430 | + void descriptionForJavaMethodAndClassSourcesUsingTechnicalNames() throws Exception { |
418 | 431 | DummyTestEngine engine = new DummyTestEngine("dummy"); |
419 | 432 | Method failingTest = getClass().getDeclaredMethod("failingTest"); |
420 | | - engine.addTest(failingTest, () -> { |
421 | | - }); |
| 433 | + DummyTestDescriptor containerDescriptor = engine.addContainer("uniqueContainerName", "containerDisplayName", |
| 434 | + new JavaClassSource(getClass())); |
| 435 | + containerDescriptor.addChild( |
| 436 | + new DummyTestDescriptor(containerDescriptor.getUniqueId().append("test", "failingTest"), |
| 437 | + "testDisplayName", new JavaMethodSource(failingTest), () -> { |
| 438 | + })); |
422 | 439 |
|
423 | 440 | JUnitPlatform platformRunner = new JUnitPlatform(TestClassWithTechnicalNames.class, createLauncher(engine)); |
424 | 441 |
|
425 | | - ArrayList<Description> children = platformRunner.getDescription().getChildren(); |
| 442 | + List<Description> children = platformRunner.getDescription().getChildren(); |
426 | 443 | assertEquals(1, children.size()); |
427 | 444 | Description engineDescription = children.get(0); |
428 | 445 | assertEquals("dummy", engineDescription.getDisplayName()); |
429 | 446 |
|
430 | | - children = engineDescription.getChildren(); |
431 | | - assertEquals(1, children.size()); |
432 | | - Description testDescription = children.get(0); |
| 447 | + Description containerDescription = getOnlyElement(engineDescription.getChildren()); |
| 448 | + Description testDescription = getOnlyElement(containerDescription.getChildren()); |
| 449 | + |
433 | 450 | // @formatter:off |
434 | 451 | assertAll( |
435 | | - () -> assertEquals(getClass().getName(), testDescription.getClassName(), "class name"), |
436 | | - () -> assertEquals("failingTest", testDescription.getMethodName(), "method name"), |
437 | | - () -> assertEquals("failingTest(" + getClass().getName() + ")", testDescription.getDisplayName(), "display name") |
| 452 | + () -> assertEquals("dummy", engineDescription.getDisplayName(), "engine display name"), |
| 453 | + () -> assertEquals("dummy", engineDescription.getClassName(), "engine class name"), |
| 454 | + () -> assertNull(engineDescription.getMethodName(), "engine method name"), |
| 455 | + () -> assertEquals(getClass().getName(), containerDescription.getDisplayName(), "container display name"), |
| 456 | + () -> assertEquals(getClass().getName(), containerDescription.getClassName(), "container class name"), |
| 457 | + () -> assertNull(containerDescription.getMethodName(), "container method name"), |
| 458 | + () -> assertEquals("failingTest(" + getClass().getName() + ")", testDescription.getDisplayName(), "test display name"), |
| 459 | + () -> assertEquals(getClass().getName(), testDescription.getClassName(), "test class name"), |
| 460 | + () -> assertEquals("failingTest", testDescription.getMethodName(), "test method name") |
438 | 461 | ); |
439 | 462 | // @formatter:on |
440 | 463 | } |
|
0 commit comments