Skip to content

Commit 613470c

Browse files
committed
Merge pull request #30514 from chessvivek
* gh-30514: Polish "Remove assumptions about ordering when comparing JSON in tests" Remove assumptions about ordering when comparing JSON in tests Closes gh-30514
2 parents 70fa7e5 + b88f062 commit 613470c

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ dependencies {
233233
testImplementation("org.junit.jupiter:junit-jupiter")
234234
testImplementation("org.mockito:mockito-core")
235235
testImplementation("org.mockito:mockito-junit-jupiter")
236+
testImplementation("org.skyscreamer:jsonassert")
236237
testImplementation("org.springframework:spring-test")
237238
testImplementation("org.springframework.kafka:spring-kafka-test")
238239
testImplementation("org.springframework.security:spring-security-test")

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,6 +29,7 @@
2929
import com.google.gson.GsonBuilder;
3030
import com.google.gson.LongSerializationPolicy;
3131
import org.junit.jupiter.api.Test;
32+
import org.skyscreamer.jsonassert.JSONAssert;
3233

3334
import org.springframework.boot.autoconfigure.AutoConfigurations;
3435
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
@@ -150,7 +151,7 @@ void additionalGsonBuilderCustomization() {
150151
void customGsonBuilder() {
151152
this.contextRunner.withUserConfiguration(GsonBuilderConfig.class).run((context) -> {
152153
Gson gson = context.getBean(Gson.class);
153-
assertThat(gson.toJson(new DataObject())).isEqualTo("{\"data\":1,\"owner\":null}");
154+
JSONAssert.assertEquals("{\"data\":1,\"owner\":null}", gson.toJson(new DataObject()), true);
154155
});
155156
}
156157

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
3030
import org.junit.jupiter.api.AfterEach;
3131
import org.junit.jupiter.api.BeforeEach;
3232
import org.junit.jupiter.api.Test;
33+
import org.skyscreamer.jsonassert.JSONAssert;
3334

3435
import org.springframework.boot.LazyInitializationBeanFactoryPostProcessor;
3536
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
@@ -101,7 +102,7 @@ void tearDown() {
101102
@Test
102103
void basicMessagingWithJsonResponse() throws Throwable {
103104
Object result = performStompSubscription("/app/json");
104-
assertThat(new String((byte[]) result)).isEqualTo(String.format("{%n \"foo\" : 5,%n \"bar\" : \"baz\"%n}"));
105+
JSONAssert.assertEquals("{\"foo\" : 5,\"bar\" : \"baz\"}", new String((byte[]) result), true);
105106
}
106107

107108
@Test

0 commit comments

Comments
 (0)