Remove assumptions about ordering when comparing JSON in tests

See gh-30514
This commit is contained in:
Vivek Gupta
2022-04-03 21:00:20 -05:00
committed by Andy Wilkinson
parent 70fa7e5e93
commit 5b3bc1a936
2 changed files with 3 additions and 1 deletions

View File

@@ -233,6 +233,7 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.mockito:mockito-core")
testImplementation("org.mockito:mockito-junit-jupiter")
testImplementation("org.skyscreamer:jsonassert")
testImplementation("org.springframework:spring-test")
testImplementation("org.springframework.kafka:spring-kafka-test")
testImplementation("org.springframework.security:spring-security-test")

View File

@@ -29,6 +29,7 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.LongSerializationPolicy;
import org.junit.jupiter.api.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -150,7 +151,7 @@ class GsonAutoConfigurationTests {
void customGsonBuilder() {
this.contextRunner.withUserConfiguration(GsonBuilderConfig.class).run((context) -> {
Gson gson = context.getBean(Gson.class);
assertThat(gson.toJson(new DataObject())).isEqualTo("{\"data\":1,\"owner\":null}");
JSONAssert.assertEquals(gson.toJson(new DataObject()), "{\"data\":1,\"owner\":null}", false);
});
}