Skip to content

Commit 4bc815a

Browse files
author
xinying7
committed
fixed 9 flaky tests in PropertySerializationTest.java: 'deserializeNotReadOnlyStringProperty', 'deserializeIntegerMapProperty', 'serializeFloatProperty', 'deserializeDoubleProperty', 'serializeIntegerProperty', 'serializeLongProperty', 'deserializeLongProperty', 'deserializeFloatProperty', 'serializeIntegerMapProperty'
1 parent bc3fa15 commit 4bc815a

File tree

1 file changed

+55
-26
lines changed

1 file changed

+55
-26
lines changed

Diff for: modules/swagger-core/src/test/java/io/swagger/v3/core/serialization/properties/PropertySerializationTest.java

+55-26
Original file line numberDiff line numberDiff line change
@@ -97,45 +97,56 @@ public void serializeDoubleProperty() throws IOException {
9797
String json2 = m.writeValueAsString(p);
9898
JSONObject jsonObj1 = new JSONObject(json1);
9999
JSONObject jsonObj2 = new JSONObject(json2);
100-
101100
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
102101
}
103102

104103
@Test(description = "it should deserialize a DoubleProperty")
105104
public void deserializeDoubleProperty() throws IOException {
106-
final String json = "{\"type\":\"number\",\"format\":\"double\"}";
107-
final Schema p = m.readValue(json, Schema.class);
105+
final String json1 = "{\"type\":\"number\",\"format\":\"double\"}";
106+
final Schema p = m.readValue(json1, Schema.class);
108107
assertEquals(p.getType(), "number");
109108
assertEquals(p.getFormat(), "double");
110109
assertEquals(p.getClass(), NumberSchema.class);
111-
assertEquals(m.writeValueAsString(p), json);
110+
String json2 = m.writeValueAsString(p);
111+
JSONObject jsonObj1 = new JSONObject(json1);
112+
JSONObject jsonObj2 = new JSONObject(json2);
113+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
112114
}
113115

114116
@Test(description = "it should serialize a FloatProperty")
115117
public void serializeFloatProperty() throws IOException {
116118
final NumberSchema p = new NumberSchema()
117119
._default(new BigDecimal("1.2"));
118120
p.format("float");
119-
final String json = "{\"type\":\"number\",\"format\":\"float\",\"default\":1.2}";
120-
assertEquals(m.writeValueAsString(p), json);
121+
final String json1 = "{\"type\":\"number\",\"format\":\"float\",\"default\":1.2}";
122+
String json2 = m.writeValueAsString(p);
123+
JSONObject jsonObj1 = new JSONObject(json1);
124+
JSONObject jsonObj2 = new JSONObject(json2);
125+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
121126
}
122127

123128
@Test(description = "it should deserialize a FloatProperty")
124129
public void deserializeFloatProperty() throws IOException {
125-
final String json = "{\"type\":\"number\",\"format\":\"float\"}";
126-
final Schema p = m.readValue(json, Schema.class);
130+
final String json1 = "{\"type\":\"number\",\"format\":\"float\"}";
131+
final Schema p = m.readValue(json1, Schema.class);
127132
assertEquals(p.getType(), "number");
128133
assertEquals(p.getFormat(), "float");
129134
assertEquals(p.getClass(), NumberSchema.class);
130-
assertEquals(m.writeValueAsString(p), json);
135+
String json2 = m.writeValueAsString(p);
136+
JSONObject jsonObj1 = new JSONObject(json1);
137+
JSONObject jsonObj2 = new JSONObject(json2);
138+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
131139
}
132140

133141
@Test(description = "it should serialize an IntegerProperty")
134142
public void serializeIntegerProperty() throws IOException {
135143
final IntegerSchema p = new IntegerSchema()
136144
._default(32);
137-
final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}";
138-
assertEquals(m.writeValueAsString(p), json);
145+
final String json1 = "{\"type\":\"integer\",\"format\":\"int32\",\"default\":32}";
146+
String json2 = m.writeValueAsString(p);
147+
JSONObject jsonObj1 = new JSONObject(json1);
148+
JSONObject jsonObj2 = new JSONObject(json2);
149+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
139150
}
140151

141152
@Test(description = "it should deserialize a IntegerProperty")
@@ -156,18 +167,24 @@ public void serializeLongProperty() throws IOException {
156167
final IntegerSchema p = new IntegerSchema()
157168
.format("int64")
158169
._default(8675309);
159-
final String json = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}";
160-
assertEquals(m.writeValueAsString(p), json);
170+
final String json1 = "{\"type\":\"integer\",\"format\":\"int64\",\"default\":8675309}";
171+
String json2 = m.writeValueAsString(p);
172+
JSONObject jsonObj1 = new JSONObject(json1);
173+
JSONObject jsonObj2 = new JSONObject(json2);
174+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
161175
}
162176

163177
@Test(description = "it should deserialize a LongProperty")
164178
public void deserializeLongProperty() throws IOException {
165-
final String json = "{\"type\":\"integer\",\"format\":\"int64\"}";
166-
final Schema p = m.readValue(json, Schema.class);
179+
final String json1 = "{\"type\":\"integer\",\"format\":\"int64\"}";
180+
final Schema p = m.readValue(json1, Schema.class);
167181
assertEquals(p.getType(), "integer");
168182
assertEquals(p.getFormat(), "int64");
169183
assertEquals(p.getClass(), IntegerSchema.class);
170-
assertEquals(m.writeValueAsString(p), json);
184+
String json2 = m.writeValueAsString(p);
185+
JSONObject jsonObj1 = new JSONObject(json1);
186+
JSONObject jsonObj2 = new JSONObject(json2);
187+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
171188
}
172189

173190
@Test(description = "it should serialize a string MapProperty")
@@ -189,17 +206,23 @@ public void deserializeStringMapProperty() throws IOException {
189206
@Test(description = "it should serialize a integer MapProperty")
190207
public void serializeIntegerMapProperty() throws IOException {
191208
final Schema p = new MapSchema().additionalProperties(new IntegerSchema());
192-
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
193-
assertEquals(m.writeValueAsString(p), json);
209+
final String json1 = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
210+
String json2 = m.writeValueAsString(p);
211+
JSONObject jsonObj1 = new JSONObject(json1);
212+
JSONObject jsonObj2 = new JSONObject(json2);
213+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
194214
}
195215

196216
@Test(description = "it should deserialize a integer MapProperty")
197217
public void deserializeIntegerMapProperty() throws IOException {
198-
final String json = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
199-
final Schema p = m.readValue(json, Schema.class);
218+
final String json1 = "{\"type\":\"object\",\"additionalProperties\":{\"type\":\"integer\",\"format\":\"int32\"}}";
219+
final Schema p = m.readValue(json1, Schema.class);
200220
assertEquals(p.getType(), "object");
201221
assertEquals(p.getClass(), MapSchema.class);
202-
assertEquals(m.writeValueAsString(p), json);
222+
String json2 = m.writeValueAsString(p);
223+
JSONObject jsonObj1 = new JSONObject(json1);
224+
JSONObject jsonObj2 = new JSONObject(json2);
225+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
203226
}
204227

205228
@Test(description = "it should serialize a long MapProperty")
@@ -281,14 +304,17 @@ public void deserializeEnumStringProperty() throws IOException {
281304

282305
@Test(description = "it should deserialize an IntegerProperty with enums")
283306
public void deserializeEnumIntegerProperty() throws IOException {
284-
final String json = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
285-
final Schema p = m.readValue(json, Schema.class);
307+
final String json1 = "{\"type\":\"integer\",\"format\":\"int32\",\"enum\":[1,2]}";
308+
final Schema p = m.readValue(json1, Schema.class);
286309
assertEquals(p.getType(), "integer");
287310
List<Number> _enum = ((IntegerSchema) p).getEnum();
288311
assertNotNull(_enum);
289312
assertEquals(_enum, Arrays.asList(1, 2));
290313
assertEquals(p.getClass(), IntegerSchema.class);
291-
assertEquals(m.writeValueAsString(p), json);
314+
String json2 = m.writeValueAsString(p);
315+
JSONObject jsonObj1 = new JSONObject(json1);
316+
JSONObject jsonObj2 = new JSONObject(json2);
317+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
292318
}
293319

294320
@Test(description = "it should serialize a string array property")
@@ -327,8 +353,11 @@ public void serializeReadOnlyStringProperty() throws IOException {
327353
public void deserializeNotReadOnlyStringProperty() throws IOException {
328354
final StringSchema p = new StringSchema();
329355
p.setReadOnly(false);
330-
final String json = "{\"type\":\"string\",\"readOnly\":false}";
331-
assertEquals(m.writeValueAsString(p), json);
356+
final String json1 = "{\"type\":\"string\",\"readOnly\":false}";
357+
String json2 = m.writeValueAsString(p);
358+
JSONObject jsonObj1 = new JSONObject(json1);
359+
JSONObject jsonObj2 = new JSONObject(json2);
360+
JSONAssert.assertEquals(jsonObj1, jsonObj2, true);
332361
}
333362

334363
@Test(description = "it should serialize an object property with required set")

0 commit comments

Comments
 (0)