From 54d51da2ce4f71acf810ec8db5c81d07456bf3b4 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sat, 20 Jan 2024 11:24:31 +0100 Subject: [PATCH 1/4] Add test for the bound check --- .../module/domain/properties/JHipsterServerPortTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java b/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java index 969aeba0196..e3fbb6458b2 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java @@ -1,9 +1,12 @@ package tech.jhipster.lite.module.domain.properties; import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertThrows; import org.junit.jupiter.api.Test; import tech.jhipster.lite.UnitTest; +import tech.jhipster.lite.shared.error.domain.NumberValueTooHighException; +import tech.jhipster.lite.shared.error.domain.NumberValueTooLowException; @UnitTest class JHipsterServerPortTest { @@ -18,6 +21,12 @@ void shouldGetServerPortFromPort() { assertThat(new JHipsterServerPort(9000).get()).isEqualTo(9000); } + @Test + void shouldValidatePortNumbers() { + assertThrows(NumberValueTooHighException.class, () -> new JHipsterServerPort(90000)); + assertThrows(NumberValueTooLowException.class, () -> new JHipsterServerPort(-90000)); + } + @Test void testToStringShowsPortNumber() { assertThat(new JHipsterServerPort(9000)).hasToString("9000"); From 902f466f845a3303d8bf4a150b1b310d1d1a6af5 Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sat, 20 Jan 2024 12:07:58 +0100 Subject: [PATCH 2/4] Use npmVersions.getNodeVersion() --- .../frontendmaven/domain/FrontendMavenModuleFactory.java | 2 +- .../frontendmaven/domain/FrontendMavenModuleFactoryTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java index 326799c1049..28395700d3a 100644 --- a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java +++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java @@ -38,7 +38,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) { //@formatter:off return moduleBuilder(properties) .javaDependencies() - .setVersion(javaDependencyVersion("node", "v" + npmVersions.get("node", NpmVersionSource.COMMON).get())) + .setVersion(javaDependencyVersion("node", "v" + npmVersions.getNodeVersion())) .setVersion(javaDependencyVersion("npm", npmVersions.get("npm", NpmVersionSource.COMMON).get())) .and() .mavenPlugins() diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java index 4966ff96672..a3a20bb2ad8 100644 --- a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java +++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java @@ -37,7 +37,7 @@ void shouldBuildModule() { .build(); when(npmVersions.get("npm", NpmVersionSource.COMMON)).thenReturn(new NpmPackageVersion("4.0.0")); - when(npmVersions.get("node", NpmVersionSource.COMMON)).thenReturn(new NpmPackageVersion("16.0.0")); + when(npmVersions.getNodeVersion()).thenReturn("16.0.0"); JHipsterModule module = factory.buildModule(properties); From d56eb15607c5c72501162e4eedb99d7f7b1c3eaa Mon Sep 17 00:00:00 2001 From: Zsombor Gegesy Date: Sat, 20 Jan 2024 13:41:54 +0100 Subject: [PATCH 3/4] Use assertj assertions, and make it a bit more verbose --- .../properties/JHipsterServerPortTest.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java b/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java index e3fbb6458b2..f22b8e9d270 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java @@ -1,9 +1,11 @@ package tech.jhipster.lite.module.domain.properties; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertThrows; +import java.util.List; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import tech.jhipster.lite.UnitTest; import tech.jhipster.lite.shared.error.domain.NumberValueTooHighException; import tech.jhipster.lite.shared.error.domain.NumberValueTooLowException; @@ -21,14 +23,20 @@ void shouldGetServerPortFromPort() { assertThat(new JHipsterServerPort(9000).get()).isEqualTo(9000); } - @Test - void shouldValidatePortNumbers() { - assertThrows(NumberValueTooHighException.class, () -> new JHipsterServerPort(90000)); - assertThrows(NumberValueTooLowException.class, () -> new JHipsterServerPort(-90000)); + @ParameterizedTest + @MethodSource("validations") + void shouldValidatePortNumbers(Setup setup) { + assertThatExceptionOfType(setup.exceptionType).isThrownBy(() -> new JHipsterServerPort(setup.number)); } @Test void testToStringShowsPortNumber() { assertThat(new JHipsterServerPort(9000)).hasToString("9000"); } + + static List validations() { + return List.of(new Setup(90000, NumberValueTooHighException.class), new Setup(-90000, NumberValueTooLowException.class)); + } + + record Setup(int number, Class exceptionType) {} } From a0577f91934e630c88c764d2541b7891cef47505 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Mino?= Date: Sat, 20 Jan 2024 14:26:16 +0100 Subject: [PATCH 4/4] Simplify parametrized test --- .../properties/JHipsterServerPortTest.java | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java b/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java index f22b8e9d270..9a13d900b30 100644 --- a/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java +++ b/src/test/java/tech/jhipster/lite/module/domain/properties/JHipsterServerPortTest.java @@ -1,14 +1,12 @@ package tech.jhipster.lite.module.domain.properties; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import java.util.List; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.CsvSource; import tech.jhipster.lite.UnitTest; -import tech.jhipster.lite.shared.error.domain.NumberValueTooHighException; -import tech.jhipster.lite.shared.error.domain.NumberValueTooLowException; @UnitTest class JHipsterServerPortTest { @@ -24,19 +22,18 @@ void shouldGetServerPortFromPort() { } @ParameterizedTest - @MethodSource("validations") - void shouldValidatePortNumbers(Setup setup) { - assertThatExceptionOfType(setup.exceptionType).isThrownBy(() -> new JHipsterServerPort(setup.number)); + @CsvSource( + { + "-90000,tech.jhipster.lite.shared.error.domain.NumberValueTooLowException", + "90000,tech.jhipster.lite.shared.error.domain.NumberValueTooHighException", + } + ) + void shouldValidatePortNumbers(int port, Class exceptionClass) { + assertThatExceptionOfType(exceptionClass).isThrownBy(() -> new JHipsterServerPort(port)); } @Test void testToStringShowsPortNumber() { assertThat(new JHipsterServerPort(9000)).hasToString("9000"); } - - static List validations() { - return List.of(new Setup(90000, NumberValueTooHighException.class), new Setup(-90000, NumberValueTooLowException.class)); - } - - record Setup(int number, Class exceptionType) {} }