Harmonize the use of Writer rather than Generator
This commit is contained in:
@@ -45,11 +45,11 @@ import org.springframework.util.MimeType;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link FileNativeConfigurationGenerator}.
|
||||
* Tests for {@link FileNativeConfigurationWriter}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class FileNativeConfigurationGeneratorTests {
|
||||
public class FileNativeConfigurationWriterTests {
|
||||
|
||||
@TempDir
|
||||
static Path tempDir;
|
||||
@@ -57,19 +57,19 @@ public class FileNativeConfigurationGeneratorTests {
|
||||
@Test
|
||||
void emptyConfig() {
|
||||
Path empty = tempDir.resolve("empty");
|
||||
FileNativeConfigurationGenerator generator = new FileNativeConfigurationGenerator(empty);
|
||||
generator.generate(new RuntimeHints());
|
||||
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(empty);
|
||||
generator.write(new RuntimeHints());
|
||||
assertThat(empty.toFile().listFiles()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializationConfig() throws IOException, JSONException {
|
||||
FileNativeConfigurationGenerator generator = new FileNativeConfigurationGenerator(tempDir);
|
||||
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(tempDir);
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
JavaSerializationHints serializationHints = hints.javaSerialization();
|
||||
serializationHints.registerType(Integer.class);
|
||||
serializationHints.registerType(Long.class);
|
||||
generator.generate(hints);
|
||||
generator.write(hints);
|
||||
assertEquals("""
|
||||
[
|
||||
{ "name": "java.lang.Integer" },
|
||||
@@ -79,12 +79,12 @@ public class FileNativeConfigurationGeneratorTests {
|
||||
|
||||
@Test
|
||||
void proxyConfig() throws IOException, JSONException {
|
||||
FileNativeConfigurationGenerator generator = new FileNativeConfigurationGenerator(tempDir);
|
||||
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(tempDir);
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
ProxyHints proxyHints = hints.proxies();
|
||||
proxyHints.registerJdkProxy(Function.class);
|
||||
proxyHints.registerJdkProxy(Function.class, Consumer.class);
|
||||
generator.generate(hints);
|
||||
generator.write(hints);
|
||||
assertEquals("""
|
||||
[
|
||||
{ "interfaces": [ "java.util.function.Function" ] },
|
||||
@@ -94,7 +94,7 @@ public class FileNativeConfigurationGeneratorTests {
|
||||
|
||||
@Test
|
||||
void reflectionConfig() throws IOException, JSONException {
|
||||
FileNativeConfigurationGenerator generator = new FileNativeConfigurationGenerator(tempDir);
|
||||
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(tempDir);
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
ReflectionHints reflectionHints = hints.reflection();
|
||||
reflectionHints.registerType(StringDecoder.class, builder -> {
|
||||
@@ -117,7 +117,7 @@ public class FileNativeConfigurationGeneratorTests {
|
||||
.withMethod("getDefaultCharset", Collections.emptyList(), constructorHint ->
|
||||
constructorHint.withMode(ExecutableMode.INTROSPECT));
|
||||
});
|
||||
generator.generate(hints);
|
||||
generator.write(hints);
|
||||
assertEquals("""
|
||||
[
|
||||
{
|
||||
@@ -152,12 +152,12 @@ public class FileNativeConfigurationGeneratorTests {
|
||||
|
||||
@Test
|
||||
void resourceConfig() throws IOException, JSONException {
|
||||
FileNativeConfigurationGenerator generator = new FileNativeConfigurationGenerator(tempDir);
|
||||
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(tempDir);
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
ResourceHints resourceHints = hints.resources();
|
||||
resourceHints.registerPattern("com/example/test.properties");
|
||||
resourceHints.registerPattern("com/example/another.properties");
|
||||
generator.generate(hints);
|
||||
generator.write(hints);
|
||||
assertEquals("""
|
||||
{
|
||||
"resources": {
|
||||
@@ -174,11 +174,11 @@ public class FileNativeConfigurationGeneratorTests {
|
||||
String groupId = "foo.bar";
|
||||
String artifactId = "baz";
|
||||
String filename = "resource-config.json";
|
||||
FileNativeConfigurationGenerator generator = new FileNativeConfigurationGenerator(tempDir, groupId, artifactId);
|
||||
FileNativeConfigurationWriter generator = new FileNativeConfigurationWriter(tempDir, groupId, artifactId);
|
||||
RuntimeHints hints = new RuntimeHints();
|
||||
ResourceHints resourceHints = hints.resources();
|
||||
resourceHints.registerPattern("com/example/test.properties");
|
||||
generator.generate(hints);
|
||||
generator.write(hints);
|
||||
Path jsonFile = tempDir.resolve("META-INF").resolve("native-image").resolve(groupId).resolve(artifactId).resolve(filename);
|
||||
assertThat(jsonFile.toFile().exists()).isTrue();
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.aot.nativex;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
@@ -26,13 +28,11 @@ import org.springframework.aot.hint.TypeReference;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* Tests for {@link JavaSerializationHintsSerializer}.
|
||||
* Tests for {@link JavaSerializationHintsWriter}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class JavaSerializationHintsSerializerTests {
|
||||
|
||||
private final JavaSerializationHintsSerializer serializer = new JavaSerializationHintsSerializer();
|
||||
public class JavaSerializationHintsWriterTests {
|
||||
|
||||
@Test
|
||||
void empty() throws JSONException {
|
||||
@@ -62,7 +62,10 @@ public class JavaSerializationHintsSerializerTests {
|
||||
}
|
||||
|
||||
private void assertEquals(String expectedString, JavaSerializationHints hints) throws JSONException {
|
||||
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
||||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
JavaSerializationHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.aot.nativex;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -27,13 +28,11 @@ import org.skyscreamer.jsonassert.JSONCompareMode;
|
||||
import org.springframework.aot.hint.ProxyHints;
|
||||
|
||||
/**
|
||||
* Tests for {@link ProxyHintsSerializer}.
|
||||
* Tests for {@link ProxyHintsWriter}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class ProxyHintsSerializerTests {
|
||||
|
||||
private final ProxyHintsSerializer serializer = new ProxyHintsSerializer();
|
||||
public class ProxyHintsWriterTests {
|
||||
|
||||
@Test
|
||||
void empty() throws JSONException {
|
||||
@@ -64,8 +63,10 @@ public class ProxyHintsSerializerTests {
|
||||
}
|
||||
|
||||
private void assertEquals(String expectedString, ProxyHints hints) throws JSONException {
|
||||
|
||||
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
||||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
ProxyHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.aot.nativex;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -33,13 +34,11 @@ import org.springframework.core.codec.StringDecoder;
|
||||
import org.springframework.util.MimeType;
|
||||
|
||||
/**
|
||||
* Tests for {@link ReflectionHintsSerializer}.
|
||||
* Tests for {@link ReflectionHintsWriter}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class ReflectionHintsSerializerTests {
|
||||
|
||||
private final ReflectionHintsSerializer serializer = new ReflectionHintsSerializer();
|
||||
public class ReflectionHintsWriterTests {
|
||||
|
||||
@Test
|
||||
void empty() throws JSONException {
|
||||
@@ -158,6 +157,7 @@ public class ReflectionHintsSerializerTests {
|
||||
]
|
||||
""", hints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void methodAndQueriedMethods() throws JSONException {
|
||||
ReflectionHints hints = new ReflectionHints();
|
||||
@@ -188,7 +188,10 @@ public class ReflectionHintsSerializerTests {
|
||||
}
|
||||
|
||||
private void assertEquals(String expectedString, ReflectionHints hints) throws JSONException {
|
||||
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
||||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
ReflectionHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.aot.nativex;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.skyscreamer.jsonassert.JSONAssert;
|
||||
@@ -24,13 +26,11 @@ import org.skyscreamer.jsonassert.JSONCompareMode;
|
||||
import org.springframework.aot.hint.ResourceHints;
|
||||
|
||||
/**
|
||||
* Tests for {@link ResourceHintsSerializer}.
|
||||
* Tests for {@link ResourceHintsWriter}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class ResourceHintsSerializerTests {
|
||||
|
||||
private final ResourceHintsSerializer serializer = new ResourceHintsSerializer();
|
||||
public class ResourceHintsWriterTests {
|
||||
|
||||
@Test
|
||||
void empty() throws JSONException {
|
||||
@@ -117,7 +117,10 @@ public class ResourceHintsSerializerTests {
|
||||
}
|
||||
|
||||
private void assertEquals(String expectedString, ResourceHints hints) throws JSONException {
|
||||
JSONAssert.assertEquals(expectedString, serializer.serialize(hints), JSONCompareMode.LENIENT);
|
||||
StringWriter out = new StringWriter();
|
||||
BasicJsonWriter writer = new BasicJsonWriter(out, "\t");
|
||||
ResourceHintsWriter.INSTANCE.write(writer, hints);
|
||||
JSONAssert.assertEquals(expectedString, out.toString(), JSONCompareMode.LENIENT);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user