Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit test for regression fix (#1651) #1655

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading