Skip to content

Commit

Permalink
Add unit test for regression fix (#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
erik-brangs authored and iloveeclipse committed Oct 29, 2024
1 parent 348433b commit ff925b8
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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";
Expand Down

0 comments on commit ff925b8

Please sign in to comment.