From 789394b61b06d452e522ea34e5221a9972b09d53 Mon Sep 17 00:00:00 2001 From: Renan Franca Date: Tue, 24 Sep 2024 11:43:33 -0300 Subject: [PATCH] refactor(preset): delete ModulesSlugs.java from the "project" bounded context and use JHipsterModuleSlugs.java from the "module" bounded context instead --- .../module/domain/JHipsterModuleSlugs.java | 14 ++++++++++ .../lite/module/domain/preset/Preset.java | 4 +-- .../primary/RestModuleToApply.java | 4 +-- .../secondary/PersistedPreset.java | 4 +-- .../lite/project/domain/ModulesSlugs.java | 14 ---------- .../primary/RestPresetsTest.java | 8 +++--- ...ileSystemJHipsterPresetRepositoryTest.java | 28 +++++++++---------- 7 files changed, 38 insertions(+), 38 deletions(-) create mode 100644 src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleSlugs.java delete mode 100644 src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java diff --git a/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleSlugs.java b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleSlugs.java new file mode 100644 index 00000000000..ec5eacbe314 --- /dev/null +++ b/src/main/java/tech/jhipster/lite/module/domain/JHipsterModuleSlugs.java @@ -0,0 +1,14 @@ +package tech.jhipster.lite.module.domain; + +import java.util.Collection; +import tech.jhipster.lite.shared.error.domain.Assert; + +public record JHipsterModuleSlugs(Collection modules) { + public JHipsterModuleSlugs { + Assert.notEmpty("modules", modules); + } + + public static JHipsterModuleSlugs from(Collection modules) { + return new JHipsterModuleSlugs(modules.stream().map(JHipsterModuleSlug::new).toList()); + } +} diff --git a/src/main/java/tech/jhipster/lite/module/domain/preset/Preset.java b/src/main/java/tech/jhipster/lite/module/domain/preset/Preset.java index e6ba1236989..98ba0e5525b 100644 --- a/src/main/java/tech/jhipster/lite/module/domain/preset/Preset.java +++ b/src/main/java/tech/jhipster/lite/module/domain/preset/Preset.java @@ -1,9 +1,9 @@ package tech.jhipster.lite.module.domain.preset; -import tech.jhipster.lite.project.domain.ModulesSlugs; +import tech.jhipster.lite.module.domain.JHipsterModuleSlugs; import tech.jhipster.lite.shared.error.domain.Assert; -public record Preset(PresetName name, ModulesSlugs modules) { +public record Preset(PresetName name, JHipsterModuleSlugs modules) { public Preset { Assert.notNull("name", name); Assert.notNull("modules", modules); diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestModuleToApply.java b/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestModuleToApply.java index 4b5129f360f..4d92c2ae1dc 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestModuleToApply.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/primary/RestModuleToApply.java @@ -1,11 +1,11 @@ package tech.jhipster.lite.module.infrastructure.primary; import io.swagger.v3.oas.annotations.media.Schema; -import tech.jhipster.lite.project.domain.ModuleSlug; +import tech.jhipster.lite.module.domain.JHipsterModuleSlug; @Schema(name = "ModuleToApply", description = "Information for a module to apply") record RestModuleToApply(@Schema(description = "Slug of the module to apply") String slug) { - public static RestModuleToApply from(ModuleSlug moduleSlug) { + public static RestModuleToApply from(JHipsterModuleSlug moduleSlug) { return new RestModuleToApply(moduleSlug.get()); } } diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/PersistedPreset.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/PersistedPreset.java index 64537cf2d24..c0caf3f4ebd 100644 --- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/PersistedPreset.java +++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/PersistedPreset.java @@ -1,12 +1,12 @@ package tech.jhipster.lite.module.infrastructure.secondary; import java.util.Collection; +import tech.jhipster.lite.module.domain.JHipsterModuleSlugs; import tech.jhipster.lite.module.domain.preset.Preset; import tech.jhipster.lite.module.domain.preset.PresetName; -import tech.jhipster.lite.project.domain.ModulesSlugs; record PersistedPreset(String name, Collection modules) { public Preset toDomain() { - return new Preset(PresetName.from(name), ModulesSlugs.from(modules)); + return new Preset(PresetName.from(name), JHipsterModuleSlugs.from(modules)); } } diff --git a/src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java b/src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java deleted file mode 100644 index 996babf4e15..00000000000 --- a/src/main/java/tech/jhipster/lite/project/domain/ModulesSlugs.java +++ /dev/null @@ -1,14 +0,0 @@ -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/test/java/tech/jhipster/lite/module/infrastructure/primary/RestPresetsTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestPresetsTest.java index 39847d1950e..7acbfd6c948 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestPresetsTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/primary/RestPresetsTest.java @@ -7,10 +7,10 @@ import org.junit.jupiter.api.Test; import tech.jhipster.lite.JsonHelper; import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.module.domain.JHipsterModuleSlug; +import tech.jhipster.lite.module.domain.JHipsterModuleSlugs; import tech.jhipster.lite.module.domain.preset.Preset; import tech.jhipster.lite.module.domain.preset.PresetName; -import tech.jhipster.lite.project.domain.ModuleSlug; -import tech.jhipster.lite.project.domain.ModulesSlugs; @UnitTest class RestPresetsTest { @@ -24,11 +24,11 @@ private static Collection presets() { return List.of( new Preset( new PresetName("test preset one"), - new ModulesSlugs(List.of(new ModuleSlug("test-module-one"), new ModuleSlug("test-module-two"))) + new JHipsterModuleSlugs(List.of(new JHipsterModuleSlug("test-module-one"), new JHipsterModuleSlug("test-module-two"))) ), new Preset( new PresetName("test preset two"), - new ModulesSlugs(List.of(new ModuleSlug("test-module-three"), new ModuleSlug("test-module-four"))) + new JHipsterModuleSlugs(List.of(new JHipsterModuleSlug("test-module-three"), new JHipsterModuleSlug("test-module-four"))) ) ); } diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterPresetRepositoryTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterPresetRepositoryTest.java index 9f13e786b8b..5595e8d3e53 100644 --- a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterPresetRepositoryTest.java +++ b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/FileSystemJHipsterPresetRepositoryTest.java @@ -10,11 +10,11 @@ import org.junit.jupiter.api.Test; import tech.jhipster.lite.JsonHelper; import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.module.domain.JHipsterModuleSlug; +import tech.jhipster.lite.module.domain.JHipsterModuleSlugs; import tech.jhipster.lite.module.domain.ProjectFiles; import tech.jhipster.lite.module.domain.preset.Preset; import tech.jhipster.lite.module.domain.preset.PresetName; -import tech.jhipster.lite.project.domain.ModuleSlug; -import tech.jhipster.lite.project.domain.ModulesSlugs; import tech.jhipster.lite.shared.error.domain.GeneratorException; @UnitTest @@ -95,19 +95,19 @@ private static ProjectFiles mockProjectFilesWithValidPresetJson() { private static Preset expectedPreset() { return new Preset( new PresetName("angular + spring boot"), - new ModulesSlugs( + new JHipsterModuleSlugs( 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 JHipsterModuleSlug("init"), + new JHipsterModuleSlug("application-service-hexagonal-architecture-documentation"), + new JHipsterModuleSlug("maven-java"), + new JHipsterModuleSlug("prettier"), + new JHipsterModuleSlug("angular-core"), + new JHipsterModuleSlug("java-base"), + new JHipsterModuleSlug("maven-wrapper"), + new JHipsterModuleSlug("spring-boot"), + new JHipsterModuleSlug("spring-boot-mvc-empty"), + new JHipsterModuleSlug("logs-spy"), + new JHipsterModuleSlug("spring-boot-tomcat") ) ) );