Make JSON assertions more strict
This commit is contained in:
parent
f65136dd68
commit
10dc10dbf9
|
|
@ -46,7 +46,7 @@ class ResourceHintsWriter {
|
|||
|
||||
public void write(BasicJsonWriter writer, ResourceHints hints) {
|
||||
Map<String, Object> attributes = new LinkedHashMap<>();
|
||||
attributes.put("resources", toAttributes(hints));
|
||||
addIfNotEmpty(attributes, "resources", toAttributes(hints));
|
||||
handleResourceBundles(attributes, hints.resourceBundles());
|
||||
writer.writeObject(attributes);
|
||||
}
|
||||
|
|
@ -81,7 +81,17 @@ class ResourceHintsWriter {
|
|||
}
|
||||
|
||||
private void addIfNotEmpty(Map<String, Object> attributes, String name, @Nullable Object value) {
|
||||
if (value != null && (value instanceof Collection<?> collection && !collection.isEmpty())) {
|
||||
if (value instanceof Collection<?> collection) {
|
||||
if (!collection.isEmpty()) {
|
||||
attributes.put(name, value);
|
||||
}
|
||||
}
|
||||
else if (value instanceof Map<?, ?> map) {
|
||||
if (!map.isEmpty()) {
|
||||
attributes.put(name, value);
|
||||
}
|
||||
}
|
||||
else if (value != null) {
|
||||
attributes.put(name, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ public class FileNativeConfigurationWriterTests {
|
|||
],
|
||||
"queriedMethods": [
|
||||
{ "name": "<init>", "parameterTypes": [ "java.util.List", "boolean", "org.springframework.util.MimeType" ] },
|
||||
{ "name": "getDefaultCharset" }
|
||||
{ "name": "getDefaultCharset", "parameterTypes": [ ] }
|
||||
]
|
||||
}
|
||||
]""", "reflect-config.json");
|
||||
|
|
@ -186,7 +186,7 @@ public class FileNativeConfigurationWriterTests {
|
|||
private void assertEquals(String expectedString, String filename) throws IOException, JSONException {
|
||||
Path jsonFile = tempDir.resolve("META-INF").resolve("native-image").resolve(filename);
|
||||
String content = new String(Files.readAllBytes(jsonFile));
|
||||
JSONAssert.assertEquals(expectedString, content, JSONCompareMode.LENIENT);
|
||||
JSONAssert.assertEquals(expectedString, content, JSONCompareMode.NON_EXTENSIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class JavaSerializationHintsWriterTests {
|
|||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
JavaSerializationHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.NON_EXTENSIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class ProxyHintsWriterTests {
|
|||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
ProxyHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.NON_EXTENSIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class ReflectionHintsWriterTests {
|
|||
],
|
||||
"queriedMethods": [
|
||||
{ "name": "<init>", "parameterTypes": [ "java.util.List", "boolean", "org.springframework.util.MimeType" ] },
|
||||
{ "name": "getDefaultCharset" }
|
||||
{ "name": "getDefaultCharset", "parameterTypes": [ ] }
|
||||
]
|
||||
}
|
||||
]""", hints);
|
||||
|
|
@ -191,7 +191,7 @@ public class ReflectionHintsWriterTests {
|
|||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
ReflectionHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.NON_EXTENSIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ public class ResourceHintsWriterTests {
|
|||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
ResourceHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.NON_EXTENSIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue