mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -28,7 +28,10 @@ import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.StringReader;
|
||||
import java.math.BigDecimal;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@@ -143,6 +146,37 @@ public class JSONObjectTest {
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBytesTest() {
|
||||
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
JSONObject json = new JSONObject(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseReaderTest() {
|
||||
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
final StringReader stringReader = new StringReader(jsonStr);
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
JSONObject json = new JSONObject(stringReader);
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseInputStreamTest() {
|
||||
String jsonStr = "{'msg':'这里还没有内容','data':{'cards':[]},'ok':0}";
|
||||
final ByteArrayInputStream in = new ByteArrayInputStream(jsonStr.getBytes(StandardCharsets.UTF_8));
|
||||
|
||||
//noinspection MismatchedQueryAndUpdateOfCollection
|
||||
JSONObject json = new JSONObject(in);
|
||||
Assert.assertEquals(new Integer(0), json.getInt("ok"));
|
||||
Assert.assertEquals(new JSONArray(), json.getJSONObject("data").getJSONArray("cards"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void parseStringWithBomTest() {
|
||||
|
Reference in New Issue
Block a user