Skip to content

Commit 6eee522

Browse files
committed
Add null-check for customTypesMapping
1 parent 21e7973 commit 6eee522

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/main/java/com/kobylynskyi/graphql/codegen/model/MappingConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ public class MappingConfig {
2121
private String modelNameSuffix;
2222

2323
public void putCustomTypeMappingIfAbsent(String from, String to) {
24+
if (customTypesMapping == null) {
25+
customTypesMapping = new HashMap<>();
26+
}
2427
if (!customTypesMapping.containsKey(from)) {
2528
customTypesMapping.put(from, to);
2629
}

src/test/java/com/kobylynskyi/graphql/codegen/GraphqlCodegenTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ void generate_NoCustomMappings() throws Exception {
110110
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString("String createdDateTime;"));
111111
}
112112

113+
@Test
114+
void generate_NullCustomMappings() throws Exception {
115+
mappingConfig.setCustomTypesMapping(null);
116+
generator.generate();
117+
118+
File[] files = Objects.requireNonNull(outputJavaClassesDir.listFiles());
119+
File eventFile = Arrays.stream(files)
120+
.filter(file -> file.getName().equalsIgnoreCase("Event.java"))
121+
.findFirst().orElseThrow(FileNotFoundException::new);
122+
123+
assertThat(Utils.getFileContent(eventFile.getPath()), StringContains.containsString("String createdDateTime;"));
124+
}
125+
113126
@Test
114127
void generate_NoPackage() throws Exception {
115128
mappingConfig.setPackageName(null);

0 commit comments

Comments
 (0)