插件开发工具库,推荐依赖该工具库。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
1.1 KiB

package com.fanruan.api.json;
import com.fr.json.JSONArray;
import com.fr.json.JSONObject;
import com.fr.third.guava.collect.Lists;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
public class JSONKitTest {
@Test
public void create() throws Exception{
Assert.assertEquals(JSONKit.create(), new JSONObject());
Assert.assertEquals(JSONKit.create("{test:123}"), new JSONObject("{test:123}"));
Map<String, Object> map = new HashMap<>();
map.put("start", 1);
map.put("end", 2);
JSONObject jsonObject = JSONKit.create(map);
Assert.assertEquals(2, jsonObject.get("end"));
JSONArray jsonArray = JSONKit.createJSONArray("[{test:123},{test:234}]");
Assert.assertEquals(123, jsonArray.getJSONObject(0).get("test"));
JSONArray jsonArray1 = JSONKit.createJSONArray(Lists.newArrayList("a", "b", "c"));
Assert.assertEquals(3, jsonArray1.length());
JSONArray jsonArray2 = JSONKit.createJSONArray();
Assert.assertEquals(0, jsonArray2.length());
}
}