提交 73a342e6 编写于 作者: B Bogdan Kobylynskyi

Add test to show how to generate nullable types instead of primitives #1023

上级 58f10612
......@@ -12,8 +12,10 @@ import org.junit.jupiter.api.extension.ExtendWith;
import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Objects;
import static com.kobylynskyi.graphql.codegen.TestUtils.assertFileContainsElements;
import static com.kobylynskyi.graphql.codegen.TestUtils.assertSameTrimmedContent;
import static com.kobylynskyi.graphql.codegen.TestUtils.getFileByName;
......@@ -98,6 +100,26 @@ class GraphQLCodegenOptionalTest {
getFileByName(files, "TypeWithMandatoryField.java"));
}
/**
* @see <a href="https://github.com/kobylynskyi/graphql-java-codegen/issues/1023">Related issue in GitHub</a>
*/
@Test
void generate_ObjectsInsteadOfPrimitives() throws Exception {
mappingConfig.setCustomTypesMapping(new HashMap<String, String>() {{
put("Int!", "Integer");
}});
schemaFinder.setIncludePattern("optional-vs-mandatory-types.graphqls");
generate();
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
// Integer is generated instead of int
assertFileContainsElements(files, "TypeWithMandatoryField.java",
" @javax.validation.constraints.NotNull",
" private Integer test;");
}
private void generate() throws IOException {
new JavaGraphQLCodegen(schemaFinder.findSchemas(), outputBuildDir, mappingConfig,
TestUtils.getStaticGeneratedInfo(mappingConfig)).generate();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册