From ff925b8b124d1200e9fca651ef133ea122deb800 Mon Sep 17 00:00:00 2001 From: Erik Brangs Date: Tue, 17 Sep 2024 20:13:09 +0200 Subject: [PATCH] Add unit test for regression fix (#1651) --- ...dJUnitLaunchConfigurationDelegateTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/launcher/AdvancedJUnitLaunchConfigurationDelegateTest.java b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/launcher/AdvancedJUnitLaunchConfigurationDelegateTest.java index 7f340d50589..1335326cbb5 100644 --- a/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/launcher/AdvancedJUnitLaunchConfigurationDelegateTest.java +++ b/org.eclipse.jdt.ui.tests/ui/org/eclipse/jdt/junit/launcher/AdvancedJUnitLaunchConfigurationDelegateTest.java @@ -145,6 +145,34 @@ public void mySecondTest() { } assertThat(fileLines).contains(lineForFirstTest, lineForSecondTest).size().isEqualTo(2); } + @Test + public void runTestsInSourceFolderHandlesPackagesWithCompilationUnitsWithoutTopLevelClassCorrectly() throws Exception { + String projectName= "JUnitLaunchConfigurationDelegate-TestProject-NoTopLevelClassInPackage"; + fJavaProject= JavaProjectHelper.createJavaProject(projectName, "bin"); + String firstTestSrcFolder= "test-src1"; + IPackageFragmentRoot testSrc1= JavaProjectHelper.addSourceContainer(fJavaProject, firstTestSrcFolder); + String testPackage= "p1"; + IPackageFragment packageTestSrc1= testSrc1.createPackageFragment(testPackage, true, null); + String contentsTestSrc1Test= """ + public class FirstTest { + @org.junit.jupiter.api.Test + public void myTest() { } + } + """; + String secondTestPackage= "p2"; + packageTestSrc1.createCompilationUnit("package-info.java", contentsTestSrc1Test, true, null); + IPackageFragment packageTestSrc2= testSrc1.createPackageFragment(secondTestPackage, true, null); + String contentsTestSrc2Test= """ + /** This is a package-info.java and thus does not have a top-level type */ + package p2; + """; + packageTestSrc2.createCompilationUnit("SecondTest.java", contentsTestSrc2Test, true, null); + + List fileLines= showCommandLineAndExtractContentOfTestNameFile(projectName, fJavaProject, testSrc1); + String lineForFirstTest= "p1.FirstTest"; + assertThat(fileLines).contains(lineForFirstTest).size().isEqualTo(1); + } + @Test public void runTestsInSourceFolderOnlyUsesTopLevelClasses() throws Exception { String projectName= "JUnitLaunchConfigurationDelegate-TestProject-OnlyTopLevelClasses";