|
21 | 21 | import org.junit.platform.launcher.TestPlan; |
22 | 22 | import org.junit.runners.model.TestTimedOutException; |
23 | 23 |
|
| 24 | +import javax.swing.text.html.Option; |
24 | 25 | import java.io.PrintStream; |
25 | 26 | import java.lang.annotation.Annotation; |
26 | 27 | import java.util.ArrayList; |
@@ -179,23 +180,27 @@ private void handleUnknownError() { |
179 | 180 | write(new StartTestcase(Message.plain("Unknown Error"))); |
180 | 181 | } |
181 | 182 |
|
182 | | - // Helper to determine if an ID is a "Tab" (Test Class) |
183 | | - private boolean isTab(TestIdentifier testIdentifier) { |
184 | | - if (!testIdentifier.isContainer() || testPlan == null || testIdentifier.getSource().isEmpty()) { |
185 | | - return false; |
| 183 | + private Optional<TestSource> getParentSource(TestIdentifier testIdentifier) { |
| 184 | + Optional<TestIdentifier> parent = testPlan.getParent(testIdentifier); |
| 185 | + // Sometimes there are intermediate parents that have an empty source, |
| 186 | + // so the direct parent of an identifier is not always a "real" parent |
| 187 | + while (parent.isPresent() && parent.get().getSource().isEmpty()) { |
| 188 | + parent = testPlan.getParent(parent.get()); |
186 | 189 | } |
| 190 | + return parent.flatMap(TestIdentifier::getSource); |
| 191 | + } |
187 | 192 |
|
188 | | - String parent = testIdentifier.getParentId().orElse(""); |
189 | | - if (!parent.contains("TestSuite")) { |
| 193 | + // Helper to determine if an ID is a "Tab" (Test Class) |
| 194 | + private boolean isTab(TestIdentifier testIdentifier) { |
| 195 | + // Filter out top-level and "empty" identifiers (such as the empty Vintage runner) |
| 196 | + if (testPlan == null || testIdentifier.getSource().isEmpty()) { |
190 | 197 | return false; |
191 | 198 | } |
192 | 199 |
|
193 | | - // Identify tabs more robustly by checking the uniqueId segment type: |
194 | | - // - regular JUnit 5 classes use "[class:...]" |
195 | | - // - JUnit 4 (vintage) runners use "[runner:...]" |
196 | | - // Suites use "[suite:...]" and must NOT be tabs. |
197 | | - String uid = testIdentifier.getUniqueId(); |
198 | | - return (uid.contains("[class:") || uid.contains("[runner:")); |
| 200 | + // Direct children of the "TestSuite" class are our test classes which should become tabs |
| 201 | + return getParentSource(testIdentifier) |
| 202 | + .map(ps -> ps instanceof ClassSource && ((ClassSource) ps).getClassName().equals("TestSuite")) |
| 203 | + .orElse(false); |
199 | 204 | } |
200 | 205 |
|
201 | 206 | private String getDescription(TestIdentifier testIdentifier) { |
|
0 commit comments