Skip to content

Commit

Permalink
adds AllArgConstructor generation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slobodator committed Dec 20, 2024
1 parent a095eb5 commit 34809c9
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, File> files = generateFiles(codegen, "src/test/resources/3_0/nullable-annotation.yaml");
var file = files.get("Item.java");
Expand All @@ -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<String, File> files = generateFiles(codegen, "src/test/resources/3_0/nullable-annotation.yaml");
Expand All @@ -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<String, File> files = generateFiles(codegen, "src/test/resources/3_0/nullable-annotation.yaml");
Expand All @@ -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)"
);
}
}

0 comments on commit 34809c9

Please sign in to comment.