fix(studio): keep project directory checks behind core services
This commit is contained in:
@@ -16,6 +16,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class ProjectCatalogService implements ProjectCatalog {
|
||||
@@ -43,6 +44,11 @@ public final class ProjectCatalogService implements ProjectCatalog {
|
||||
return projectsRoot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Path> existingProjectsRoot() {
|
||||
return Files.isDirectory(projectsRoot) ? Optional.of(projectsRoot) : Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ProjectReference> listProjects() {
|
||||
if (!Files.isDirectory(projectsRoot)) {
|
||||
|
||||
+27
@@ -11,12 +11,39 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ProjectCatalogServiceTest {
|
||||
@TempDir
|
||||
Path tempDir;
|
||||
|
||||
@Test
|
||||
void exposesExistingProjectsDirectoryWithoutChangingConfiguredRoot() {
|
||||
final ProjectCatalogService service = service(tempDir.resolve("child/.."));
|
||||
|
||||
assertEquals(tempDir.toAbsolutePath().normalize(), service.existingProjectsRoot().orElseThrow());
|
||||
assertEquals(service.projectsRoot(), service.existingProjectsRoot().orElseThrow());
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotCreateMissingProjectsRootForDirectorySelection() {
|
||||
final Path missing = tempDir.resolve("missing");
|
||||
final ProjectCatalogService service = service(missing);
|
||||
|
||||
assertTrue(service.existingProjectsRoot().isEmpty());
|
||||
assertEquals(missing.toAbsolutePath().normalize(), service.projectsRoot());
|
||||
assertFalse(Files.exists(missing));
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotOfferRegularFileAsProjectsDirectory() throws Exception {
|
||||
final Path file = Files.writeString(tempDir.resolve("projects"), "not a directory");
|
||||
|
||||
assertTrue(service(file).existingProjectsRoot().isEmpty());
|
||||
assertEquals("not a directory", Files.readString(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsAndReopensAProjectWithLocalSetup() throws Exception {
|
||||
final ProjectCatalogService service = service(tempDir);
|
||||
|
||||
Reference in New Issue
Block a user