Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request alibaba#3570 from MengdiGao/fix-test-Issue3082
Browse files Browse the repository at this point in the history
Fix 3 flaky tests caused by Map ordering assumption
  • Loading branch information
wenshao committed Jul 10, 2021
2 parents 23070b2 + 3ec1a75 commit 433398d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public void test_for_multimap() throws Exception {
map.put("name", "b");

String json = JSON.toJSONString(map);
assertEquals("{\"name\":[\"a\",\"b\"]}", json);
assertTrue(json.equals("{\"name\":[\"a\",\"b\"]}") || json.equals("{\"name\":[\"b\",\"a\"]}"));
}
}
10 changes: 8 additions & 2 deletions src/test/java/com/alibaba/json/bvt/issue_1500/Issue1584.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ public void test_for_issue() throws Exception {

{
Map.Entry entry = JSON.parseObject(json, Map.Entry.class, config);
assertEquals("v", entry.getKey());
assertEquals("A", entry.getValue());
Object key = entry.getKey();
Object value = entry.getValue();
assertTrue(key.equals("v") || key.equals("k"));
if (key.equals("v")) {
assertEquals("A", value);
} else {
assertEquals(1, value);
}
}

config.putDeserializer(Map.Entry.class, new ObjectDeserializer() {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/alibaba/json/bvt/issue_3000/Issue3082.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.lang.reflect.Type;
Expand All @@ -26,6 +27,6 @@ public void test_for_issue() throws Exception {
HashSet<Map.Entry<String, Map.Entry<String, String>>> deserializedNestedSet;
Type type = new TypeReference<HashSet<Map.Entry<String, Map.Entry<String, String>>>>() {}.getType();
deserializedNestedSet = JSON.parseObject(content, type);
assertEquals("b", deserializedNestedSet.iterator().next().getValue().getKey());
assertEquals(nestedSet, deserializedNestedSet);
}
}

0 comments on commit 433398d

Please sign in to comment.