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#3530 from MengdiGao/fix-JSONPath_reverse_test
Browse files Browse the repository at this point in the history
Fix flaky test JSONPath_reverse_test
  • Loading branch information
wenshao committed Jul 10, 2021
2 parents 433398d + 133cca0 commit 6e956d2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/test/java/com/alibaba/json/bvt/path/JSONPath_reverse_test.java
Expand Up @@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

public class JSONPath_reverse_test extends TestCase
Expand All @@ -12,7 +13,13 @@ public void test_reserve() throws Exception {

assertEquals("[1001,\"ljw\"]", JSONPath.reserveToArray(object, "id", "name").toString());
assertEquals("[\"ljw\",1001]", JSONPath.reserveToArray(object, "name", "id").toString());
assertEquals("[\"ljw\",[\"ljw\",1001,50]]", JSONPath.reserveToArray(object, "name", "*").toString());
String text = JSON.toJSONString(JSONPath.reserveToArray(object, "name", "*"), SerializerFeature.MapSortField);
assertTrue(text.equals("[\"ljw\",[\"ljw\",1001,50]]")
|| text.equals("[\"ljw\",[\"ljw\",50,1001]]")
|| text.equals("[\"ljw\",[50,1001,\"ljw\"]]")
|| text.equals("[\"ljw\",[1001,50,\"ljw\"]]")
|| text.equals("[\"ljw\",[1001,\"ljw\",50]]")
|| text.equals("[\"ljw\",[50,\"ljw\",1001]]"));
}

public void test_reserve2() throws Exception {
Expand All @@ -26,8 +33,10 @@ public void test_reserve2() throws Exception {
public void test_reserve3() throws Exception {
JSONObject object = JSON.parseObject("{\"player\":{\"id\":1001,\"name\":\"ljw\",\"age\":50}}");

assertEquals("{\"player\":{\"name\":\"ljw\",\"id\":1001}}", JSONPath.reserveToObject(object, "player.id", "player.name").toString());
assertEquals("{\"player\":{\"name\":\"ljw\",\"id\":1001}}", JSONPath.reserveToObject(object, "player.name", "player.id", "ab.c").toString());
String text = JSON.toJSONString(JSONPath.reserveToObject(object, "player.id", "player.name"), SerializerFeature.MapSortField);
assertEquals("{\"player\":{\"id\":1001,\"name\":\"ljw\"}}", text);
text = JSON.toJSONString(JSONPath.reserveToObject(object, "player.name", "player.id", "ab.c"), SerializerFeature.MapSortField);
assertEquals("{\"player\":{\"id\":1001,\"name\":\"ljw\"}}", text);
}


Expand Down

0 comments on commit 6e956d2

Please sign in to comment.