-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #857 from XIAYM-gh/master
Implemented custom duplicate key handling (#840)
- Loading branch information
Showing
4 changed files
with
170 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/org/json/junit/JSONParserConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.json.junit; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.json.JSONParserConfiguration; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class JSONParserConfigurationTest { | ||
private static final String TEST_SOURCE = "{\"key\": \"value1\", \"key\": \"value2\"}"; | ||
|
||
@Test(expected = JSONException.class) | ||
public void testThrowException() { | ||
new JSONObject(TEST_SOURCE); | ||
} | ||
|
||
@Test | ||
public void testOverwrite() { | ||
JSONObject jsonObject = new JSONObject(TEST_SOURCE, new JSONParserConfiguration(true)); | ||
|
||
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key")); | ||
} | ||
|
||
@Test | ||
public void verifyDuplicateKeyThenMaxDepth() { | ||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() | ||
.withOverwriteDuplicateKey(true) | ||
.withMaxNestingDepth(42); | ||
|
||
assertEquals(42, jsonParserConfiguration.getMaxNestingDepth()); | ||
assertTrue(jsonParserConfiguration.isOverwriteDuplicateKey()); | ||
} | ||
|
||
@Test | ||
public void verifyMaxDepthThenDuplicateKey() { | ||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration() | ||
.withMaxNestingDepth(42) | ||
.withOverwriteDuplicateKey(true); | ||
|
||
assertTrue(jsonParserConfiguration.isOverwriteDuplicateKey()); | ||
assertEquals(42, jsonParserConfiguration.getMaxNestingDepth()); | ||
} | ||
} |