From f9593124f42c004b350735ee451131537103dfea Mon Sep 17 00:00:00 2001 From: Andriy Slobodyanyk Date: Fri, 20 Dec 2024 13:20:28 +0400 Subject: [PATCH] adds AllArgConstructor generation tests --- .../codegen/java/spring/SpringCodegenTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java index bbb36bcd30a3..f20f77cafae4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java @@ -5104,6 +5104,7 @@ public void testEnumUnknownDefaultCaseDeserializationNotSet_issue13241() throws public void shouldAnnotateNonRequiredFieldsAsNullable() throws IOException { SpringCodegen codegen = new SpringCodegen(); codegen.setLibrary(SPRING_BOOT); + codegen.setGenerateConstructorWithAllArgs(true); Map files = generateFiles(codegen, "src/test/resources/3_0/nullable-annotation.yaml"); var file = files.get("Item.java"); @@ -5120,12 +5121,18 @@ public void shouldAnnotateNonRequiredFieldsAsNullable() throws IOException { JavaFileAssert.assertThat(file) .assertProperty("nullableStr") .doesNotHaveAnnotation("Nullable"); + JavaFileAssert.assertThat(file) + .fileContains( + "public Item(String mandatoryName, @Nullable String optionalDescription," + + " String optionalOneWithDefault, String nullableStr)" + ); } @Test public void shouldNotAnnotateNonRequiredFieldsAsNullableWhileUseOptional() throws IOException { SpringCodegen codegen = new SpringCodegen(); codegen.setLibrary(SPRING_BOOT); + codegen.setGenerateConstructorWithAllArgs(true); codegen.setUseOptional(true); Map files = generateFiles(codegen, "src/test/resources/3_0/nullable-annotation.yaml"); @@ -5143,12 +5150,18 @@ public void shouldNotAnnotateNonRequiredFieldsAsNullableWhileUseOptional() throw JavaFileAssert.assertThat(file) .assertProperty("nullableStr") .doesNotHaveAnnotation("Nullable"); + JavaFileAssert.assertThat(file) + .fileContains( + "public Item(String mandatoryName, String optionalDescription," + + " String optionalOneWithDefault, String nullableStr)" + ); } @Test public void shouldAnnotateNonRequiredFieldsAsNullableWhileNotUsingOpenApiNullable() throws IOException { SpringCodegen codegen = new SpringCodegen(); codegen.setLibrary(SPRING_BOOT); + codegen.setGenerateConstructorWithAllArgs(true); codegen.setOpenApiNullable(false); Map files = generateFiles(codegen, "src/test/resources/3_0/nullable-annotation.yaml"); @@ -5166,5 +5179,10 @@ public void shouldAnnotateNonRequiredFieldsAsNullableWhileNotUsingOpenApiNullabl JavaFileAssert.assertThat(file) .assertProperty("nullableStr") .hasAnnotation("Nullable"); + JavaFileAssert.assertThat(file) + .fileContains( + "public Item(String mandatoryName, @Nullable String optionalDescription," + + " String optionalOneWithDefault, @Nullable String nullableStr)" + ); } }