Revert some unnecessary changes (mentioned in #840)

This commit is contained in:
XIAYM-gh
2024-02-14 17:53:58 +08:00
parent 21a9fae7b0
commit cb2c8d3962
4 changed files with 22 additions and 106 deletions

View File

@@ -7,41 +7,17 @@ import static org.junit.Assert.*;
import org.junit.Test;
public class JSONObjectDuplicateKeyTest {
private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\", \"key\": \"value3\"}";
private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\"}";
@Test(expected = JSONException.class)
public void testThrowException() {
new JSONObject(TEST_SOURCE);
}
@Test
public void testIgnore() {
JSONObject jsonObject = new JSONObject(TEST_SOURCE, new JSONParserConfiguration(
JSONDuplicateKeyStrategy.IGNORE
));
assertEquals("duplicate key shouldn't be overwritten", "value1", jsonObject.getString("key"));
}
@Test
public void testOverwrite() {
JSONObject jsonObject = new JSONObject(TEST_SOURCE, new JSONParserConfiguration(
JSONDuplicateKeyStrategy.OVERWRITE
));
JSONObject jsonObject = new JSONObject(TEST_SOURCE, new JSONParserConfiguration(true));
assertEquals("duplicate key should be overwritten", "value3", jsonObject.getString("key"));
}
@Test
public void testMergeIntoArray() {
JSONObject jsonObject = new JSONObject(TEST_SOURCE, new JSONParserConfiguration(
JSONDuplicateKeyStrategy.MERGE_INTO_ARRAY
));
JSONArray jsonArray;
assertTrue("duplicate key should be merged into JSONArray", jsonObject.get("key") instanceof JSONArray
&& (jsonArray = jsonObject.getJSONArray("key")).length() == 3
&& jsonArray.getString(0).equals("value1") && jsonArray.getString(1).equals("value2")
&& jsonArray.getString(2).equals("value3"));
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key"));
}
}