mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 19:15:27 -04:00
test(#871-strictMode): add two more test which validate error correctness
This commit is contained in:
parent
8f66865e0a
commit
d335447ab4
@ -23,7 +23,7 @@ public class JSONParserConfigurationTest {
|
||||
@Test
|
||||
public void testOverwrite() {
|
||||
JSONObject jsonObject = new JSONObject(TEST_SOURCE,
|
||||
new JSONParserConfiguration().withOverwriteDuplicateKey(true));
|
||||
new JSONParserConfiguration().withOverwriteDuplicateKey(true));
|
||||
|
||||
assertEquals("duplicate key should be overwritten", "value2", jsonObject.getString("key"));
|
||||
}
|
||||
@ -48,6 +48,42 @@ public class JSONParserConfigurationTest {
|
||||
strictModeInputTestCases.forEach(testCase -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInvalidInputArray_testStrictModeTrue_shouldThrowInvalidCharacterErrorMessage() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[1,2];[3,4]";
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("invalid character found after end of array: ; at 6 [character 7 line 1]", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInvalidInputArray_testStrictModeTrue_shouldThrowValueNotSurroundedByQuotesErrorMessage() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[{\"test\": implied}]";
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("Value is not surrounded by quotes: implied", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenInvalidInputArray_testStrictModeTrue_shouldThrowKeyNotSurroundedByQuotesErrorMessage() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
.withStrictMode(true);
|
||||
|
||||
String testCase = "[{test: implied}]";
|
||||
JSONException je = assertThrows("expected non-compliant array but got instead: " + testCase,
|
||||
JSONException.class, () -> new JSONArray(testCase, jsonParserConfiguration));
|
||||
|
||||
assertEquals("Key is not surrounded by quotes: test", je.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifyDuplicateKeyThenMaxDepth() {
|
||||
JSONParserConfiguration jsonParserConfiguration = new JSONParserConfiguration()
|
||||
|
Loading…
x
Reference in New Issue
Block a user