From 06b8116ae9ddc17e9172945cb888fe899cf3b3b1 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Fri, 12 Jul 2024 12:10:08 -0300 Subject: [PATCH 01/17] feat: read presets from json file --- .../lite/project/domain/preset/Preset.java | 5 +++ .../secondary/FileSystemPresetRepository.java | 25 ++++++++++++ .../FileSystemPresetRepositoryTest.java | 38 +++++++++++++++++++ .../resources/projects/preset/preset.json | 18 +++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java create mode 100644 src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java create mode 100644 src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java create mode 100644 src/test/resources/projects/preset/preset.json diff --git a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java new file mode 100644 index 00000000000..726dc2dc988 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java @@ -0,0 +1,5 @@ +package tech.jhipster.lite.project.domain.preset; + +import java.util.Collection; + +public record Preset(String name, Collection modules) {} diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java new file mode 100644 index 00000000000..3fe8a3e90f6 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -0,0 +1,25 @@ +package tech.jhipster.lite.project.infrastructure.secondary; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Collection; +import java.util.List; +import tech.jhipster.lite.project.domain.preset.Preset; +import tech.jhipster.lite.shared.error.domain.GeneratorException; + +class FileSystemPresetRepository { + + public Collection get(String path) { + ObjectMapper objectMapper = new ObjectMapper(); + + try { + String jsonContent = new String(Files.readAllBytes(Paths.get(path))); + return objectMapper.readValue(jsonContent, new TypeReference>() {}); + } catch (IOException e) { + throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); + } + } +} diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java new file mode 100644 index 00000000000..a0837ab5793 --- /dev/null +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -0,0 +1,38 @@ +package tech.jhipster.lite.project.infrastructure.secondary; + +import static org.assertj.core.api.Assertions.*; + +import java.util.Collection; +import java.util.List; +import org.junit.jupiter.api.Test; +import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.project.domain.preset.Preset; + +@UnitTest +class FileSystemPresetRepositoryTest { + + @Test + void shouldGetExistingPreset() { + FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(); + + Collection presets = presetRepository.get("src/test/resources/projects/preset/preset.json"); + + Preset expectedPreset = new Preset( + "angular + spring boot", + List.of( + "init", + "application-service-hexagonal-architecture-documentation", + "maven-java", + "prettier", + "angular-core", + "java-base", + "maven-wrapper", + "spring-boot", + "spring-boot-mvc-empty", + "logs-spy", + "spring-boot-tomcat" + ) + ); + assertThat(presets).containsExactly(expectedPreset); + } +} diff --git a/src/test/resources/projects/preset/preset.json b/src/test/resources/projects/preset/preset.json new file mode 100644 index 00000000000..14b2d3787c4 --- /dev/null +++ b/src/test/resources/projects/preset/preset.json @@ -0,0 +1,18 @@ +[ + { + "name": "angular + spring boot", + "modules": [ + "init", + "application-service-hexagonal-architecture-documentation", + "maven-java", + "prettier", + "angular-core", + "java-base", + "maven-wrapper", + "spring-boot", + "spring-boot-mvc-empty", + "logs-spy", + "spring-boot-tomcat" + ] + } +] From 23b10e4f82cb8bcc32ed69a8cc013250fe382a5a Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 11:29:55 -0300 Subject: [PATCH 02/17] feat: preset name can not be null or empty --- .../lite/project/domain/preset/Preset.java | 7 +++- .../project/domain/preset/PresetName.java | 13 +++++++ .../secondary/FileSystemPresetRepository.java | 4 +- .../secondary/PersistedPreset.java | 11 ++++++ .../secondary/PersistedPresets.java | 11 ++++++ .../FileSystemPresetRepositoryTest.java | 3 +- .../resources/projects/preset/preset.json | 38 ++++++++++--------- 7 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 src/main/java/tech/jhipster/lite/project/domain/preset/PresetName.java create mode 100644 src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java create mode 100644 src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPresets.java diff --git a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java index 726dc2dc988..30a737ecb1e 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java +++ b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java @@ -1,5 +1,10 @@ package tech.jhipster.lite.project.domain.preset; import java.util.Collection; +import tech.jhipster.lite.shared.error.domain.Assert; -public record Preset(String name, Collection modules) {} +public record Preset(PresetName name, Collection modules) { + public Preset { + Assert.notNull("name", name); + } +} diff --git a/src/main/java/tech/jhipster/lite/project/domain/preset/PresetName.java b/src/main/java/tech/jhipster/lite/project/domain/preset/PresetName.java new file mode 100644 index 00000000000..85b036c9f15 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/project/domain/preset/PresetName.java @@ -0,0 +1,13 @@ +package tech.jhipster.lite.project.domain.preset; + +import tech.jhipster.lite.shared.error.domain.Assert; + +public record PresetName(String name) { + public PresetName { + Assert.notBlank("name", name); + } + + public static PresetName from(String name) { + return new PresetName(name); + } +} diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 3fe8a3e90f6..51d9869a8ad 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -1,12 +1,10 @@ package tech.jhipster.lite.project.infrastructure.secondary; -import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collection; -import java.util.List; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.shared.error.domain.GeneratorException; @@ -17,7 +15,7 @@ public Collection get(String path) { try { String jsonContent = new String(Files.readAllBytes(Paths.get(path))); - return objectMapper.readValue(jsonContent, new TypeReference>() {}); + return objectMapper.readValue(jsonContent, PersistedPresets.class).toDomain(); } catch (IOException e) { throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); } diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java new file mode 100644 index 00000000000..23526159fda --- /dev/null +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java @@ -0,0 +1,11 @@ +package tech.jhipster.lite.project.infrastructure.secondary; + +import java.util.Collection; +import tech.jhipster.lite.project.domain.preset.Preset; +import tech.jhipster.lite.project.domain.preset.PresetName; + +record PersistedPreset(String name, Collection modules) { + public Preset toDomain() { + return new Preset(PresetName.from(name), modules); + } +} diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPresets.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPresets.java new file mode 100644 index 00000000000..1b385a1bede --- /dev/null +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPresets.java @@ -0,0 +1,11 @@ +package tech.jhipster.lite.project.infrastructure.secondary; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collection; +import tech.jhipster.lite.project.domain.preset.Preset; + +record PersistedPresets(@JsonProperty("presets") Collection presets) { + public Collection toDomain() { + return presets.stream().map(PersistedPreset::toDomain).toList(); + } +} diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index a0837ab5793..909973b266d 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.project.domain.preset.Preset; +import tech.jhipster.lite.project.domain.preset.PresetName; @UnitTest class FileSystemPresetRepositoryTest { @@ -18,7 +19,7 @@ void shouldGetExistingPreset() { Collection presets = presetRepository.get("src/test/resources/projects/preset/preset.json"); Preset expectedPreset = new Preset( - "angular + spring boot", + new PresetName("angular + spring boot"), List.of( "init", "application-service-hexagonal-architecture-documentation", diff --git a/src/test/resources/projects/preset/preset.json b/src/test/resources/projects/preset/preset.json index 14b2d3787c4..edb3e921968 100644 --- a/src/test/resources/projects/preset/preset.json +++ b/src/test/resources/projects/preset/preset.json @@ -1,18 +1,20 @@ -[ - { - "name": "angular + spring boot", - "modules": [ - "init", - "application-service-hexagonal-architecture-documentation", - "maven-java", - "prettier", - "angular-core", - "java-base", - "maven-wrapper", - "spring-boot", - "spring-boot-mvc-empty", - "logs-spy", - "spring-boot-tomcat" - ] - } -] +{ + "presets": [ + { + "name": "angular + spring boot", + "modules": [ + "init", + "application-service-hexagonal-architecture-documentation", + "maven-java", + "prettier", + "angular-core", + "java-base", + "maven-wrapper", + "spring-boot", + "spring-boot-mvc-empty", + "logs-spy", + "spring-boot-tomcat" + ] + } + ] +} From 036b287ff0d843f2bce1ba7ef6357108ead58105 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 11:50:43 -0300 Subject: [PATCH 03/17] feat: preset modules can not be null or empty --- .../domain/{history => }/ModuleSlug.java | 2 +- .../project/domain/history/ProjectAction.java | 1 + .../lite/project/domain/preset/Preset.java | 4 +++- .../secondary/PersistedPreset.java | 3 ++- .../FileSystemPresetRepositoryTest.java | 23 ++++++++++--------- 5 files changed, 19 insertions(+), 14 deletions(-) rename src/main/java/tech/jhipster/lite/project/domain/{history => }/ModuleSlug.java (80%) diff --git a/src/main/java/tech/jhipster/lite/project/domain/history/ModuleSlug.java b/src/main/java/tech/jhipster/lite/project/domain/ModuleSlug.java similarity index 80% rename from src/main/java/tech/jhipster/lite/project/domain/history/ModuleSlug.java rename to src/main/java/tech/jhipster/lite/project/domain/ModuleSlug.java index 2eefaed4648..3b1e8ac2af8 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/history/ModuleSlug.java +++ b/src/main/java/tech/jhipster/lite/project/domain/ModuleSlug.java @@ -1,4 +1,4 @@ -package tech.jhipster.lite.project.domain.history; +package tech.jhipster.lite.project.domain; import tech.jhipster.lite.shared.error.domain.Assert; diff --git a/src/main/java/tech/jhipster/lite/project/domain/history/ProjectAction.java b/src/main/java/tech/jhipster/lite/project/domain/history/ProjectAction.java index 69b97ad0d68..fc89fd4547d 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/history/ProjectAction.java +++ b/src/main/java/tech/jhipster/lite/project/domain/history/ProjectAction.java @@ -2,6 +2,7 @@ import java.time.Instant; import java.util.Map; +import tech.jhipster.lite.project.domain.ModuleSlug; import tech.jhipster.lite.shared.error.domain.Assert; public final class ProjectAction { diff --git a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java index 30a737ecb1e..846ac232eff 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java +++ b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java @@ -1,10 +1,12 @@ package tech.jhipster.lite.project.domain.preset; import java.util.Collection; +import tech.jhipster.lite.project.domain.ModuleSlug; import tech.jhipster.lite.shared.error.domain.Assert; -public record Preset(PresetName name, Collection modules) { +public record Preset(PresetName name, Collection modules) { public Preset { Assert.notNull("name", name); + Assert.notEmpty("modules", modules); } } diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java index 23526159fda..59dfcbdf6ea 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java @@ -1,11 +1,12 @@ package tech.jhipster.lite.project.infrastructure.secondary; import java.util.Collection; +import tech.jhipster.lite.project.domain.ModuleSlug; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.project.domain.preset.PresetName; record PersistedPreset(String name, Collection modules) { public Preset toDomain() { - return new Preset(PresetName.from(name), modules); + return new Preset(PresetName.from(name), modules.stream().map(ModuleSlug::new).toList()); } } diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 909973b266d..92a686a6e01 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -6,6 +6,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.project.domain.ModuleSlug; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.project.domain.preset.PresetName; @@ -21,17 +22,17 @@ void shouldGetExistingPreset() { Preset expectedPreset = new Preset( new PresetName("angular + spring boot"), List.of( - "init", - "application-service-hexagonal-architecture-documentation", - "maven-java", - "prettier", - "angular-core", - "java-base", - "maven-wrapper", - "spring-boot", - "spring-boot-mvc-empty", - "logs-spy", - "spring-boot-tomcat" + new ModuleSlug("init"), + new ModuleSlug("application-service-hexagonal-architecture-documentation"), + new ModuleSlug("maven-java"), + new ModuleSlug("prettier"), + new ModuleSlug("angular-core"), + new ModuleSlug("java-base"), + new ModuleSlug("maven-wrapper"), + new ModuleSlug("spring-boot"), + new ModuleSlug("spring-boot-mvc-empty"), + new ModuleSlug("logs-spy"), + new ModuleSlug("spring-boot-tomcat") ) ); assertThat(presets).containsExactly(expectedPreset); From ef7012dae43cc5a5b1ec563e75035be411725610 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 11:58:00 -0300 Subject: [PATCH 04/17] refactor(FileSystemPresetRepository): use Path as parameter type --- .../secondary/FileSystemPresetRepository.java | 6 +++--- .../secondary/FileSystemPresetRepositoryTest.java | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 51d9869a8ad..02c9033d2d0 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -3,18 +3,18 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.file.Path; import java.util.Collection; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.shared.error.domain.GeneratorException; class FileSystemPresetRepository { - public Collection get(String path) { + public Collection get(Path path) { ObjectMapper objectMapper = new ObjectMapper(); try { - String jsonContent = new String(Files.readAllBytes(Paths.get(path))); + String jsonContent = new String(Files.readAllBytes(path)); return objectMapper.readValue(jsonContent, PersistedPresets.class).toDomain(); } catch (IOException e) { throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 92a686a6e01..df819f77cce 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -2,6 +2,7 @@ import static org.assertj.core.api.Assertions.*; +import java.nio.file.Paths; import java.util.Collection; import java.util.List; import org.junit.jupiter.api.Test; @@ -17,7 +18,7 @@ class FileSystemPresetRepositoryTest { void shouldGetExistingPreset() { FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(); - Collection presets = presetRepository.get("src/test/resources/projects/preset/preset.json"); + Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset/preset.json")); Preset expectedPreset = new Preset( new PresetName("angular + spring boot"), From b2ae15e4137d83003a9f2835ef412126d5e276fc Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 12:02:18 -0300 Subject: [PATCH 05/17] refactor(FileSystemPresetRepository): inline and simplify json conversion --- .../infrastructure/secondary/FileSystemPresetRepository.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 02c9033d2d0..35d4a7d0516 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -14,8 +14,7 @@ public Collection get(Path path) { ObjectMapper objectMapper = new ObjectMapper(); try { - String jsonContent = new String(Files.readAllBytes(path)); - return objectMapper.readValue(jsonContent, PersistedPresets.class).toDomain(); + return objectMapper.readValue(Files.readAllBytes(path), PersistedPresets.class).toDomain(); } catch (IOException e) { throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); } From da9f23ce51a5f1ee630f9ab7490e7a12c2706671 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 12:13:35 -0300 Subject: [PATCH 06/17] feat: get empty preset from unknown file --- .../secondary/FileSystemPresetRepository.java | 5 +++++ .../secondary/FileSystemPresetRepositoryTest.java | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 35d4a7d0516..47c6063b0ba 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -5,12 +5,17 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Collection; +import java.util.List; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.shared.error.domain.GeneratorException; class FileSystemPresetRepository { public Collection get(Path path) { + if (Files.notExists(path)) { + return List.of(); + } + ObjectMapper objectMapper = new ObjectMapper(); try { diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index df819f77cce..15201c1ea81 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -14,10 +14,17 @@ @UnitTest class FileSystemPresetRepositoryTest { + private static final FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(); + @Test - void shouldGetExistingPreset() { - FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(); + void shouldGetEmptyPresetFromUnknownFile() { + Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset/preset_not_exists.json")); + + assertThat(presets).isEmpty(); + } + @Test + void shouldGetExistingPreset() { Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset/preset.json")); Preset expectedPreset = new Preset( From bcf5d0354034cd1d95c5b9a39a40aeb9c106ea63 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 12:35:01 -0300 Subject: [PATCH 07/17] refactor: define preset json file name as a constant --- .../secondary/FileSystemPresetRepository.java | 12 ++++++++++-- .../secondary/FileSystemPresetRepositoryTest.java | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 47c6063b0ba..32ed7bd6474 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -11,17 +11,25 @@ class FileSystemPresetRepository { + public static final String PRESET_FILE = "preset.json"; + public Collection get(Path path) { - if (Files.notExists(path)) { + Path presetFilePath = presetFilePath(path); + + if (Files.notExists(presetFilePath)) { return List.of(); } ObjectMapper objectMapper = new ObjectMapper(); try { - return objectMapper.readValue(Files.readAllBytes(path), PersistedPresets.class).toDomain(); + return objectMapper.readValue(Files.readAllBytes(presetFilePath), PersistedPresets.class).toDomain(); } catch (IOException e) { throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); } } + + private static Path presetFilePath(Path path) { + return path.resolve(PRESET_FILE); + } } diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 15201c1ea81..88337b45efd 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -18,14 +18,14 @@ class FileSystemPresetRepositoryTest { @Test void shouldGetEmptyPresetFromUnknownFile() { - Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset/preset_not_exists.json")); + Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset-not-exists")); assertThat(presets).isEmpty(); } @Test void shouldGetExistingPreset() { - Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset/preset.json")); + Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset")); Preset expectedPreset = new Preset( new PresetName("angular + spring boot"), From 023cabfeb87283803789aa0fa555691fafeaf381 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 12:39:12 -0300 Subject: [PATCH 08/17] feat: must not be null the path to folder passed as parameter which should contains the preset json file --- .../infrastructure/secondary/FileSystemPresetRepository.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 32ed7bd6474..9eb4b284fa8 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -7,6 +7,7 @@ import java.util.Collection; import java.util.List; import tech.jhipster.lite.project.domain.preset.Preset; +import tech.jhipster.lite.shared.error.domain.Assert; import tech.jhipster.lite.shared.error.domain.GeneratorException; class FileSystemPresetRepository { @@ -14,6 +15,8 @@ class FileSystemPresetRepository { public static final String PRESET_FILE = "preset.json"; public Collection get(Path path) { + Assert.notNull("path", path); + Path presetFilePath = presetFilePath(path); if (Files.notExists(presetFilePath)) { From 8fa5a1e68b441e477e7d3624b7894bbe941eaf79 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Mon, 15 Jul 2024 13:40:54 -0300 Subject: [PATCH 09/17] feat: set the location of the preset.json file at the root of the resource's folder --- .../secondary/FileSystemPresetRepository.java | 22 +++------ .../tech/jhipster/lite/TestFileUtils.java | 2 +- .../FileSystemPresetRepositoryTest.java | 49 ++++++++++++++++--- .../resources/projects/preset/preset.json | 20 -------- 4 files changed, 51 insertions(+), 42 deletions(-) delete mode 100644 src/test/resources/projects/preset/preset.json diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 9eb4b284fa8..3171ecc4d1b 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -2,10 +2,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Collection; -import java.util.List; +import tech.jhipster.lite.module.domain.ProjectFiles; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.shared.error.domain.Assert; import tech.jhipster.lite.shared.error.domain.GeneratorException; @@ -14,25 +12,21 @@ class FileSystemPresetRepository { public static final String PRESET_FILE = "preset.json"; - public Collection get(Path path) { - Assert.notNull("path", path); + private final ProjectFiles projectFiles; - Path presetFilePath = presetFilePath(path); + public FileSystemPresetRepository(ProjectFiles projectFiles) { + Assert.notNull("projectFiles", projectFiles); - if (Files.notExists(presetFilePath)) { - return List.of(); - } + this.projectFiles = projectFiles; + } + public Collection get() { ObjectMapper objectMapper = new ObjectMapper(); try { - return objectMapper.readValue(Files.readAllBytes(presetFilePath), PersistedPresets.class).toDomain(); + return objectMapper.readValue(projectFiles.readBytes(PRESET_FILE), PersistedPresets.class).toDomain(); } catch (IOException e) { throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); } } - - private static Path presetFilePath(Path path) { - return path.resolve(PRESET_FILE); - } } diff --git a/src/test/java/tech/jhipster/lite/TestFileUtils.java b/src/test/java/tech/jhipster/lite/TestFileUtils.java index 74719853daa..55d1de2f584 100644 --- a/src/test/java/tech/jhipster/lite/TestFileUtils.java +++ b/src/test/java/tech/jhipster/lite/TestFileUtils.java @@ -1,6 +1,6 @@ package tech.jhipster.lite; -import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static java.nio.file.StandardCopyOption.*; import java.io.IOException; import java.nio.file.FileSystems; diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 88337b45efd..42a9048849d 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -1,31 +1,66 @@ package tech.jhipster.lite.project.infrastructure.secondary; import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; -import java.nio.file.Paths; import java.util.Collection; import java.util.List; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.module.domain.ProjectFiles; +import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles; import tech.jhipster.lite.project.domain.ModuleSlug; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.project.domain.preset.PresetName; +import tech.jhipster.lite.shared.error.domain.GeneratorException; @UnitTest +@ExtendWith(MockitoExtension.class) class FileSystemPresetRepositoryTest { - private static final FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(); + @Mock + private ProjectFiles projectFiles; - @Test - void shouldGetEmptyPresetFromUnknownFile() { - Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset-not-exists")); + private FileSystemPresetRepository presetRepository; - assertThat(presets).isEmpty(); + @Test + void shouldNotReturnPresetFromUnknownFile() { + presetRepository = new FileSystemPresetRepository(new FileSystemProjectFiles()); + assertThatThrownBy(() -> presetRepository.get()).isExactlyInstanceOf(GeneratorException.class); } @Test void shouldGetExistingPreset() { - Collection presets = presetRepository.get(Paths.get("src/test/resources/projects/preset")); + presetRepository = new FileSystemPresetRepository(projectFiles); + String jsonContent = + """ + { + "presets": [ + { + "name": "angular + spring boot", + "modules": [ + "init", + "application-service-hexagonal-architecture-documentation", + "maven-java", + "prettier", + "angular-core", + "java-base", + "maven-wrapper", + "spring-boot", + "spring-boot-mvc-empty", + "logs-spy", + "spring-boot-tomcat" + ] + } + ] + } + """; + lenient().when(projectFiles.readBytes("preset.json")).thenReturn(jsonContent.getBytes()); + + Collection presets = presetRepository.get(); Preset expectedPreset = new Preset( new PresetName("angular + spring boot"), diff --git a/src/test/resources/projects/preset/preset.json b/src/test/resources/projects/preset/preset.json deleted file mode 100644 index edb3e921968..00000000000 --- a/src/test/resources/projects/preset/preset.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "presets": [ - { - "name": "angular + spring boot", - "modules": [ - "init", - "application-service-hexagonal-architecture-documentation", - "maven-java", - "prettier", - "angular-core", - "java-base", - "maven-wrapper", - "spring-boot", - "spring-boot-mvc-empty", - "logs-spy", - "spring-boot-tomcat" - ] - } - ] -} From 082cdb68e3b9c8776fbc76304847dab7005eedd4 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 09:31:56 -0300 Subject: [PATCH 10/17] refactor(FileSystemPresetRepositoryTest): improve usage of mocks --- .../FileSystemPresetRepositoryTest.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 42a9048849d..be9bea74a69 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -6,9 +6,6 @@ import java.util.Collection; import java.util.List; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.module.domain.ProjectFiles; import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles; @@ -18,12 +15,8 @@ import tech.jhipster.lite.shared.error.domain.GeneratorException; @UnitTest -@ExtendWith(MockitoExtension.class) class FileSystemPresetRepositoryTest { - @Mock - private ProjectFiles projectFiles; - private FileSystemPresetRepository presetRepository; @Test @@ -34,8 +27,7 @@ void shouldNotReturnPresetFromUnknownFile() { @Test void shouldGetExistingPreset() { - presetRepository = new FileSystemPresetRepository(projectFiles); - String jsonContent = + String validPresetJson = """ { "presets": [ @@ -58,7 +50,7 @@ void shouldGetExistingPreset() { ] } """; - lenient().when(projectFiles.readBytes("preset.json")).thenReturn(jsonContent.getBytes()); + presetRepository = new FileSystemPresetRepository(mockProjectFilesWithJson(validPresetJson.getBytes())); Collection presets = presetRepository.get(); @@ -80,4 +72,12 @@ void shouldGetExistingPreset() { ); assertThat(presets).containsExactly(expectedPreset); } + + private static ProjectFiles mockProjectFilesWithJson(byte[] bytes) { + ProjectFiles projectFiles = mock(ProjectFiles.class); + + lenient().when(projectFiles.readBytes("preset.json")).thenReturn(bytes); + + return projectFiles; + } } From a059ddb79e93ab45d8ebc1404340170d11b2d054 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 09:37:19 -0300 Subject: [PATCH 11/17] refactor(FileSystemPresetRepositoryTest): improve readability of shouldGetExistingPreset method --- .../FileSystemPresetRepositoryTest.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index be9bea74a69..cf860eef535 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -54,7 +54,19 @@ void shouldGetExistingPreset() { Collection presets = presetRepository.get(); - Preset expectedPreset = new Preset( + assertThat(presets).containsExactly(expectedPreset()); + } + + private static ProjectFiles mockProjectFilesWithJson(byte[] bytes) { + ProjectFiles projectFiles = mock(ProjectFiles.class); + + lenient().when(projectFiles.readBytes("preset.json")).thenReturn(bytes); + + return projectFiles; + } + + private static Preset expectedPreset() { + return new Preset( new PresetName("angular + spring boot"), List.of( new ModuleSlug("init"), @@ -70,14 +82,5 @@ void shouldGetExistingPreset() { new ModuleSlug("spring-boot-tomcat") ) ); - assertThat(presets).containsExactly(expectedPreset); - } - - private static ProjectFiles mockProjectFilesWithJson(byte[] bytes) { - ProjectFiles projectFiles = mock(ProjectFiles.class); - - lenient().when(projectFiles.readBytes("preset.json")).thenReturn(bytes); - - return projectFiles; } } From 3e78750fa382db54dc73be28d0e0c4866d8add2b Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 09:54:40 -0300 Subject: [PATCH 12/17] test(FileSystemPresetRepositoryTest): ensure deserialization errors are handled --- .../secondary/FileSystemPresetRepository.java | 9 ++++---- .../FileSystemPresetRepositoryTest.java | 22 +++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java index 3171ecc4d1b..ee69cb3615d 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java @@ -13,18 +13,19 @@ class FileSystemPresetRepository { public static final String PRESET_FILE = "preset.json"; private final ProjectFiles projectFiles; + private final ObjectMapper json; - public FileSystemPresetRepository(ProjectFiles projectFiles) { + public FileSystemPresetRepository(ProjectFiles projectFiles, ObjectMapper json) { Assert.notNull("projectFiles", projectFiles); + Assert.notNull("json", json); this.projectFiles = projectFiles; + this.json = json; } public Collection get() { - ObjectMapper objectMapper = new ObjectMapper(); - try { - return objectMapper.readValue(projectFiles.readBytes(PRESET_FILE), PersistedPresets.class).toDomain(); + return json.readValue(projectFiles.readBytes(PRESET_FILE), PersistedPresets.class).toDomain(); } catch (IOException e) { throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); } diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index cf860eef535..5a3c8f07f95 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -3,9 +3,12 @@ import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import java.util.Collection; import java.util.List; import org.junit.jupiter.api.Test; +import tech.jhipster.lite.JsonHelper; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.module.domain.ProjectFiles; import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles; @@ -17,12 +20,20 @@ @UnitTest class FileSystemPresetRepositoryTest { - private FileSystemPresetRepository presetRepository; + @Test + void shouldHandleDeserializationErrors() throws IOException { + ObjectMapper json = mock(ObjectMapper.class); + when(json.readValue(any(byte[].class), eq(PersistedPresets.class))).thenThrow(IOException.class); + FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(new FileSystemProjectFiles(), json); + + assertThatThrownBy(presetRepository::get).isExactlyInstanceOf(GeneratorException.class); + } @Test void shouldNotReturnPresetFromUnknownFile() { - presetRepository = new FileSystemPresetRepository(new FileSystemProjectFiles()); - assertThatThrownBy(() -> presetRepository.get()).isExactlyInstanceOf(GeneratorException.class); + FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(new FileSystemProjectFiles(), JsonHelper.jsonMapper()); + + assertThatThrownBy(presetRepository::get).isExactlyInstanceOf(GeneratorException.class); } @Test @@ -50,7 +61,10 @@ void shouldGetExistingPreset() { ] } """; - presetRepository = new FileSystemPresetRepository(mockProjectFilesWithJson(validPresetJson.getBytes())); + FileSystemPresetRepository presetRepository = new FileSystemPresetRepository( + mockProjectFilesWithJson(validPresetJson.getBytes()), + JsonHelper.jsonMapper() + ); Collection presets = presetRepository.get(); From d79a6bf0f217b1b936e23a55dcaf85d9891b264c Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 10:39:59 -0300 Subject: [PATCH 13/17] refactor: improve readability of conversion from PersistedPreset to Preset --- .../lite/project/domain/ModulesSlugs.java | 14 ++++++++++ .../lite/project/domain/preset/Preset.java | 7 +++-- .../secondary/PersistedPreset.java | 4 +-- .../FileSystemPresetRepositoryTest.java | 27 ++++++++++--------- 4 files changed, 34 insertions(+), 18 deletions(-) create mode 100644 src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java diff --git a/src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java b/src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java new file mode 100644 index 00000000000..996babf4e15 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java @@ -0,0 +1,14 @@ +package tech.jhipster.lite.project.domain; + +import java.util.Collection; +import tech.jhipster.lite.shared.error.domain.Assert; + +public record ModulesSlugs(Collection modules) { + public ModulesSlugs { + Assert.notEmpty("modules", modules); + } + + public static ModulesSlugs from(Collection modules) { + return new ModulesSlugs(modules.stream().map(ModuleSlug::new).toList()); + } +} diff --git a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java index 846ac232eff..ec083784104 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java +++ b/src/main/java/tech/jhipster/lite/project/domain/preset/Preset.java @@ -1,12 +1,11 @@ package tech.jhipster.lite.project.domain.preset; -import java.util.Collection; -import tech.jhipster.lite.project.domain.ModuleSlug; +import tech.jhipster.lite.project.domain.ModulesSlugs; import tech.jhipster.lite.shared.error.domain.Assert; -public record Preset(PresetName name, Collection modules) { +public record Preset(PresetName name, ModulesSlugs modules) { public Preset { Assert.notNull("name", name); - Assert.notEmpty("modules", modules); + Assert.notNull("modules", modules); } } diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java index 59dfcbdf6ea..ef329591988 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/PersistedPreset.java @@ -1,12 +1,12 @@ package tech.jhipster.lite.project.infrastructure.secondary; import java.util.Collection; -import tech.jhipster.lite.project.domain.ModuleSlug; +import tech.jhipster.lite.project.domain.ModulesSlugs; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.project.domain.preset.PresetName; record PersistedPreset(String name, Collection modules) { public Preset toDomain() { - return new Preset(PresetName.from(name), modules.stream().map(ModuleSlug::new).toList()); + return new Preset(PresetName.from(name), ModulesSlugs.from(modules)); } } diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 5a3c8f07f95..1bb6eb60d0b 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -13,6 +13,7 @@ import tech.jhipster.lite.module.domain.ProjectFiles; import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles; import tech.jhipster.lite.project.domain.ModuleSlug; +import tech.jhipster.lite.project.domain.ModulesSlugs; import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.project.domain.preset.PresetName; import tech.jhipster.lite.shared.error.domain.GeneratorException; @@ -82,18 +83,20 @@ private static ProjectFiles mockProjectFilesWithJson(byte[] bytes) { private static Preset expectedPreset() { return new Preset( new PresetName("angular + spring boot"), - List.of( - new ModuleSlug("init"), - new ModuleSlug("application-service-hexagonal-architecture-documentation"), - new ModuleSlug("maven-java"), - new ModuleSlug("prettier"), - new ModuleSlug("angular-core"), - new ModuleSlug("java-base"), - new ModuleSlug("maven-wrapper"), - new ModuleSlug("spring-boot"), - new ModuleSlug("spring-boot-mvc-empty"), - new ModuleSlug("logs-spy"), - new ModuleSlug("spring-boot-tomcat") + new ModulesSlugs( + List.of( + new ModuleSlug("init"), + new ModuleSlug("application-service-hexagonal-architecture-documentation"), + new ModuleSlug("maven-java"), + new ModuleSlug("prettier"), + new ModuleSlug("angular-core"), + new ModuleSlug("java-base"), + new ModuleSlug("maven-wrapper"), + new ModuleSlug("spring-boot"), + new ModuleSlug("spring-boot-mvc-empty"), + new ModuleSlug("logs-spy"), + new ModuleSlug("spring-boot-tomcat") + ) ) ); } From b1ea9a15ebc0cf37df367e5570ae0b287140e5f9 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 11:19:37 -0300 Subject: [PATCH 14/17] fix(FileSystemPresetRepositoryTest): properly handle deserialization errors by avoiding exceptions from ProjectFiles.readBytes method --- .../FileSystemPresetRepositoryTest.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java index 1bb6eb60d0b..bfbf3e29a2e 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java @@ -25,7 +25,7 @@ class FileSystemPresetRepositoryTest { void shouldHandleDeserializationErrors() throws IOException { ObjectMapper json = mock(ObjectMapper.class); when(json.readValue(any(byte[].class), eq(PersistedPresets.class))).thenThrow(IOException.class); - FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(new FileSystemProjectFiles(), json); + FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(mockProjectFilesWithValidPresetJson(), json); assertThatThrownBy(presetRepository::get).isExactlyInstanceOf(GeneratorException.class); } @@ -39,6 +39,19 @@ void shouldNotReturnPresetFromUnknownFile() { @Test void shouldGetExistingPreset() { + FileSystemPresetRepository presetRepository = new FileSystemPresetRepository( + mockProjectFilesWithValidPresetJson(), + JsonHelper.jsonMapper() + ); + + Collection presets = presetRepository.get(); + + assertThat(presets).containsExactly(expectedPreset()); + } + + private static ProjectFiles mockProjectFilesWithValidPresetJson() { + ProjectFiles projectFiles = mock(ProjectFiles.class); + String validPresetJson = """ { @@ -62,20 +75,7 @@ void shouldGetExistingPreset() { ] } """; - FileSystemPresetRepository presetRepository = new FileSystemPresetRepository( - mockProjectFilesWithJson(validPresetJson.getBytes()), - JsonHelper.jsonMapper() - ); - - Collection presets = presetRepository.get(); - - assertThat(presets).containsExactly(expectedPreset()); - } - - private static ProjectFiles mockProjectFilesWithJson(byte[] bytes) { - ProjectFiles projectFiles = mock(ProjectFiles.class); - - lenient().when(projectFiles.readBytes("preset.json")).thenReturn(bytes); + lenient().when(projectFiles.readBytes("preset.json")).thenReturn(validPresetJson.getBytes()); return projectFiles; } From d49eaa93bc912b7190a3e075f4cf6a945c552457 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 12:50:57 -0300 Subject: [PATCH 15/17] refactor(preset): move the preset logic to ProjectsRepository interface --- .../project/domain/ProjectsRepository.java | 4 + .../secondary/FileSystemPresetRepository.java | 33 ----- .../FileSystemProjectsRepository.java | 17 ++- .../FileSystemPresetRepositoryTest.java | 103 ---------------- .../FileSystemProjectsRepositoryTest.java | 115 +++++++++++++++++- 5 files changed, 132 insertions(+), 140 deletions(-) delete mode 100644 src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java delete mode 100644 src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java diff --git a/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java b/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java index f26de1b39a4..615f7b880ff 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java +++ b/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java @@ -1,8 +1,10 @@ package tech.jhipster.lite.project.domain; +import java.util.Collection; import java.util.Optional; import tech.jhipster.lite.project.domain.download.Project; import tech.jhipster.lite.project.domain.history.ProjectHistory; +import tech.jhipster.lite.project.domain.preset.Preset; public interface ProjectsRepository { void format(ProjectPath path); @@ -12,4 +14,6 @@ public interface ProjectsRepository { void save(ProjectHistory history); ProjectHistory getHistory(ProjectPath path); + + Collection getPreset(); } diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java deleted file mode 100644 index ee69cb3615d..00000000000 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -package tech.jhipster.lite.project.infrastructure.secondary; - -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.util.Collection; -import tech.jhipster.lite.module.domain.ProjectFiles; -import tech.jhipster.lite.project.domain.preset.Preset; -import tech.jhipster.lite.shared.error.domain.Assert; -import tech.jhipster.lite.shared.error.domain.GeneratorException; - -class FileSystemPresetRepository { - - public static final String PRESET_FILE = "preset.json"; - - private final ProjectFiles projectFiles; - private final ObjectMapper json; - - public FileSystemPresetRepository(ProjectFiles projectFiles, ObjectMapper json) { - Assert.notNull("projectFiles", projectFiles); - Assert.notNull("json", json); - - this.projectFiles = projectFiles; - this.json = json; - } - - public Collection get() { - try { - return json.readValue(projectFiles.readBytes(PRESET_FILE), PersistedPresets.class).toDomain(); - } catch (IOException e) { - throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); - } - } -} diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java index f285799cb12..b3fb8931dee 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java @@ -6,12 +6,15 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.Collection; import java.util.Optional; import org.springframework.stereotype.Repository; +import tech.jhipster.lite.module.domain.ProjectFiles; import tech.jhipster.lite.project.domain.ProjectPath; import tech.jhipster.lite.project.domain.ProjectsRepository; import tech.jhipster.lite.project.domain.download.Project; import tech.jhipster.lite.project.domain.history.ProjectHistory; +import tech.jhipster.lite.project.domain.preset.Preset; import tech.jhipster.lite.shared.error.domain.Assert; import tech.jhipster.lite.shared.error.domain.GeneratorException; @@ -22,15 +25,18 @@ class FileSystemProjectsRepository implements ProjectsRepository { private static final String HISTORY_FOLDER = ".jhipster/modules"; private static final String HISTORY_FILE = "history.json"; + public static final String PRESET_FILE = "preset.json"; private final ObjectMapper json; private final ProjectFormatter formatter; + private final ProjectFiles projectFiles; private final ObjectWriter writer; private final FileSystemProjectDownloader downloader; - public FileSystemProjectsRepository(ObjectMapper json, ProjectFormatter formatter) { + public FileSystemProjectsRepository(ObjectMapper json, ProjectFormatter formatter, ProjectFiles projectFiles) { this.json = json; this.formatter = formatter; + this.projectFiles = projectFiles; writer = json.writerWithDefaultPrettyPrinter(); downloader = new FileSystemProjectDownloader(); @@ -84,4 +90,13 @@ public ProjectHistory getHistory(ProjectPath path) { private Path historyFilePath(ProjectPath path) { return Paths.get(path.get(), HISTORY_FOLDER, HISTORY_FILE); } + + @Override + public Collection getPreset() { + try { + return json.readValue(projectFiles.readBytes(PRESET_FILE), PersistedPresets.class).toDomain(); + } catch (IOException e) { + throw GeneratorException.technicalError("Can't read presets: " + e.getMessage(), e); + } + } } diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java deleted file mode 100644 index bfbf3e29a2e..00000000000 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemPresetRepositoryTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package tech.jhipster.lite.project.infrastructure.secondary; - -import static org.assertj.core.api.Assertions.*; -import static org.mockito.Mockito.*; - -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.IOException; -import java.util.Collection; -import java.util.List; -import org.junit.jupiter.api.Test; -import tech.jhipster.lite.JsonHelper; -import tech.jhipster.lite.UnitTest; -import tech.jhipster.lite.module.domain.ProjectFiles; -import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles; -import tech.jhipster.lite.project.domain.ModuleSlug; -import tech.jhipster.lite.project.domain.ModulesSlugs; -import tech.jhipster.lite.project.domain.preset.Preset; -import tech.jhipster.lite.project.domain.preset.PresetName; -import tech.jhipster.lite.shared.error.domain.GeneratorException; - -@UnitTest -class FileSystemPresetRepositoryTest { - - @Test - void shouldHandleDeserializationErrors() throws IOException { - ObjectMapper json = mock(ObjectMapper.class); - when(json.readValue(any(byte[].class), eq(PersistedPresets.class))).thenThrow(IOException.class); - FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(mockProjectFilesWithValidPresetJson(), json); - - assertThatThrownBy(presetRepository::get).isExactlyInstanceOf(GeneratorException.class); - } - - @Test - void shouldNotReturnPresetFromUnknownFile() { - FileSystemPresetRepository presetRepository = new FileSystemPresetRepository(new FileSystemProjectFiles(), JsonHelper.jsonMapper()); - - assertThatThrownBy(presetRepository::get).isExactlyInstanceOf(GeneratorException.class); - } - - @Test - void shouldGetExistingPreset() { - FileSystemPresetRepository presetRepository = new FileSystemPresetRepository( - mockProjectFilesWithValidPresetJson(), - JsonHelper.jsonMapper() - ); - - Collection presets = presetRepository.get(); - - assertThat(presets).containsExactly(expectedPreset()); - } - - private static ProjectFiles mockProjectFilesWithValidPresetJson() { - ProjectFiles projectFiles = mock(ProjectFiles.class); - - String validPresetJson = - """ - { - "presets": [ - { - "name": "angular + spring boot", - "modules": [ - "init", - "application-service-hexagonal-architecture-documentation", - "maven-java", - "prettier", - "angular-core", - "java-base", - "maven-wrapper", - "spring-boot", - "spring-boot-mvc-empty", - "logs-spy", - "spring-boot-tomcat" - ] - } - ] - } - """; - lenient().when(projectFiles.readBytes("preset.json")).thenReturn(validPresetJson.getBytes()); - - return projectFiles; - } - - private static Preset expectedPreset() { - return new Preset( - new PresetName("angular + spring boot"), - new ModulesSlugs( - List.of( - new ModuleSlug("init"), - new ModuleSlug("application-service-hexagonal-architecture-documentation"), - new ModuleSlug("maven-java"), - new ModuleSlug("prettier"), - new ModuleSlug("angular-core"), - new ModuleSlug("java-base"), - new ModuleSlug("maven-wrapper"), - new ModuleSlug("spring-boot"), - new ModuleSlug("spring-boot-mvc-empty"), - new ModuleSlug("logs-spy"), - new ModuleSlug("spring-boot-tomcat") - ) - ) - ); - } -} diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java index 38ff6d9bdb3..a286c676d26 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java @@ -24,10 +24,16 @@ import tech.jhipster.lite.JsonHelper; import tech.jhipster.lite.TestFileUtils; import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.module.domain.ProjectFiles; +import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles; +import tech.jhipster.lite.project.domain.ModuleSlug; +import tech.jhipster.lite.project.domain.ModulesSlugs; import tech.jhipster.lite.project.domain.ProjectPath; import tech.jhipster.lite.project.domain.download.Project; import tech.jhipster.lite.project.domain.download.ProjectName; import tech.jhipster.lite.project.domain.history.ProjectHistory; +import tech.jhipster.lite.project.domain.preset.Preset; +import tech.jhipster.lite.project.domain.preset.PresetName; import tech.jhipster.lite.shared.error.domain.GeneratorException; @UnitTest @@ -35,7 +41,8 @@ class FileSystemProjectsRepositoryTest { private static final FileSystemProjectsRepository projects = new FileSystemProjectsRepository( JsonHelper.jsonMapper(), - mock(ProjectFormatter.class) + mock(ProjectFormatter.class), + mock(ProjectFiles.class) ); @Nested @@ -139,7 +146,11 @@ void shouldHandleSerializationError() throws JsonProcessingException { ObjectMapper json = mock(ObjectMapper.class); when(json.writerWithDefaultPrettyPrinter()).thenReturn(writer); - FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(json, mock(ProjectFormatter.class)); + FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository( + json, + mock(ProjectFormatter.class), + mock(ProjectFiles.class) + ); assertThatThrownBy(() -> fileSystemProjectsRepository.save(projectHistory())).isExactlyInstanceOf(GeneratorException.class); } @@ -178,7 +189,11 @@ void shouldHandleDeserializationErrors() throws IOException { ObjectMapper json = mock(ObjectMapper.class); when(json.readValue(any(byte[].class), eq(PersistedProjectHistory.class))).thenThrow(IOException.class); - FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository(json, mock(ProjectFormatter.class)); + FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository( + json, + mock(ProjectFormatter.class), + mock(ProjectFiles.class) + ); assertThatThrownBy(() -> fileSystemProjectsRepository.getHistory(path)).isExactlyInstanceOf(GeneratorException.class); } @@ -204,6 +219,48 @@ void shouldGetExistingHistory() { } } + @Nested + @DisplayName("Get preset") + class FileSystemProjectsRepositoryGetPresetTest { + + @Test + void shouldHandleDeserializationErrors() throws IOException { + ObjectMapper json = mock(ObjectMapper.class); + when(json.readValue(any(byte[].class), eq(PersistedPresets.class))).thenThrow(IOException.class); + FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository( + json, + mock(ProjectFormatter.class), + mockProjectFilesWithValidPresetJson() + ); + + assertThatThrownBy(fileSystemProjectsRepository::getPreset).isExactlyInstanceOf(GeneratorException.class); + } + + @Test + void shouldNotReturnPresetFromUnknownFile() { + FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository( + JsonHelper.jsonMapper(), + mock(ProjectFormatter.class), + new FileSystemProjectFiles() + ); + + assertThatThrownBy(fileSystemProjectsRepository::getPreset).isExactlyInstanceOf(GeneratorException.class); + } + + @Test + void shouldGetExistingPreset() { + FileSystemProjectsRepository fileSystemProjectsRepository = new FileSystemProjectsRepository( + JsonHelper.jsonMapper(), + mock(ProjectFormatter.class), + mockProjectFilesWithValidPresetJson() + ); + + Collection presets = fileSystemProjectsRepository.getPreset(); + + assertThat(presets).containsExactly(expectedPreset()); + } + } + private static FolderBuilder folder() { return new FolderBuilder(); } @@ -248,4 +305,56 @@ public ProjectPath build() { return new ProjectPath(folder.toString()); } } + + private static ProjectFiles mockProjectFilesWithValidPresetJson() { + ProjectFiles projectFiles = mock(ProjectFiles.class); + + String validPresetJson = + """ + { + "presets": [ + { + "name": "angular + spring boot", + "modules": [ + "init", + "application-service-hexagonal-architecture-documentation", + "maven-java", + "prettier", + "angular-core", + "java-base", + "maven-wrapper", + "spring-boot", + "spring-boot-mvc-empty", + "logs-spy", + "spring-boot-tomcat" + ] + } + ] + } + """; + lenient().when(projectFiles.readBytes("preset.json")).thenReturn(validPresetJson.getBytes()); + + return projectFiles; + } + + private static Preset expectedPreset() { + return new Preset( + new PresetName("angular + spring boot"), + new ModulesSlugs( + List.of( + new ModuleSlug("init"), + new ModuleSlug("application-service-hexagonal-architecture-documentation"), + new ModuleSlug("maven-java"), + new ModuleSlug("prettier"), + new ModuleSlug("angular-core"), + new ModuleSlug("java-base"), + new ModuleSlug("maven-wrapper"), + new ModuleSlug("spring-boot"), + new ModuleSlug("spring-boot-mvc-empty"), + new ModuleSlug("logs-spy"), + new ModuleSlug("spring-boot-tomcat") + ) + ) + ); + } } From 7303ca057e4cdd04f7816eaee1b152c9b73c42e2 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 16 Jul 2024 12:54:49 -0300 Subject: [PATCH 16/17] fix(FileSystemProjectsRepository): change constant visibility to private --- .../infrastructure/secondary/FileSystemProjectsRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java index b3fb8931dee..afc08f6fb80 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java @@ -25,7 +25,7 @@ class FileSystemProjectsRepository implements ProjectsRepository { private static final String HISTORY_FOLDER = ".jhipster/modules"; private static final String HISTORY_FILE = "history.json"; - public static final String PRESET_FILE = "preset.json"; + private static final String PRESET_FILE = "preset.json"; private final ObjectMapper json; private final ProjectFormatter formatter; From 9303ced6a26f548759470ea616e376db24f36b7e Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Thu, 18 Jul 2024 08:32:20 -0300 Subject: [PATCH 17/17] refactor(ProjectsRepository): change method signature to plural because it returns a collection --- .../jhipster/lite/project/domain/ProjectsRepository.java | 2 +- .../secondary/FileSystemProjectsRepository.java | 2 +- .../secondary/FileSystemProjectsRepositoryTest.java | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java b/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java index 615f7b880ff..a9f7a149676 100644 --- a/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java +++ b/src/main/java/tech/jhipster/lite/project/domain/ProjectsRepository.java @@ -15,5 +15,5 @@ public interface ProjectsRepository { ProjectHistory getHistory(ProjectPath path); - Collection getPreset(); + Collection getPresets(); } diff --git a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java index afc08f6fb80..cdc5d4373e8 100644 --- a/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java +++ b/src/main/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java @@ -92,7 +92,7 @@ private Path historyFilePath(ProjectPath path) { } @Override - public Collection getPreset() { + public Collection getPresets() { try { return json.readValue(projectFiles.readBytes(PRESET_FILE), PersistedPresets.class).toDomain(); } catch (IOException e) { diff --git a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java index a286c676d26..c5124ffd68e 100644 --- a/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepositoryTest.java @@ -233,7 +233,7 @@ void shouldHandleDeserializationErrors() throws IOException { mockProjectFilesWithValidPresetJson() ); - assertThatThrownBy(fileSystemProjectsRepository::getPreset).isExactlyInstanceOf(GeneratorException.class); + assertThatThrownBy(fileSystemProjectsRepository::getPresets).isExactlyInstanceOf(GeneratorException.class); } @Test @@ -244,7 +244,7 @@ void shouldNotReturnPresetFromUnknownFile() { new FileSystemProjectFiles() ); - assertThatThrownBy(fileSystemProjectsRepository::getPreset).isExactlyInstanceOf(GeneratorException.class); + assertThatThrownBy(fileSystemProjectsRepository::getPresets).isExactlyInstanceOf(GeneratorException.class); } @Test @@ -255,7 +255,7 @@ void shouldGetExistingPreset() { mockProjectFilesWithValidPresetJson() ); - Collection presets = fileSystemProjectsRepository.getPreset(); + Collection presets = fileSystemProjectsRepository.getPresets(); assertThat(presets).containsExactly(expectedPreset()); }