Add test for no build.gradle parent path
The build.gradle cannot work if it can't determine the parent directory's
base name, so to test that we need to use ROOT=/, where /build.gradle has
only a single Path element.
@@ -27,6 +27,7 @@ class ModuleDetectorTest extends ResourceTest {
private static final String MANIFEST = "MANIFEST.MF";
private static final String MANIFEST_NAME = "MANIFEST-NAME.MF";
private static final Path ROOT = Paths.get(File.pathSeparatorChar == ';' ? "C:\\Windows" : "/tmp");
+ private static final Path ROOT_ABSOLUTE = Paths.get(File.pathSeparatorChar == ';' ? "C:\\" : "/");
private static final String PREFIX = new PathUtil().getAbsolutePath(ROOT) + "/";
private static final int NO_RESULT = 0;
@@ -345,6 +346,19 @@ class ModuleDetectorTest extends ResourceTest {
.isEqualTo(EXPECTED_GRADLE_MODULE_ROOT_BY_PATH);
}
+ @Test
+ void shouldIgnoreGradleFileWithNoParentPath() {
+ FileSystem factory = createFileSystemStub(stub -> {
+ when(stub.find(any(), anyString())).thenReturn(new String[] {
+ ModuleDetector.BUILD_GRADLE,
+ });
+ });
+
+ ModuleDetector detector = new ModuleDetector(ROOT_ABSOLUTE, factory);
+ assertThat(detector.guessModuleName("build/reports/something.txt"))
+ .isEqualTo(StringUtils.EMPTY);
+ }
+
@Test
void shouldIdentifyModuleByReadingAntProjectFile() {
FileSystem factory = createFileSystemStub(stub -> {
