mirror of
https://github.com/stleary/JSON-java.git
synced 2025-08-02 19:15:27 -04:00
add new test cases for JSONObject and JSONArray Constructors with JSONTokener and strict mode
This commit is contained in:
parent
3b7ba07531
commit
ad44a9274c
@ -4,6 +4,7 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONParserConfiguration;
|
import org.json.JSONParserConfiguration;
|
||||||
|
import org.json.JSONTokener;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -490,6 +491,40 @@ public class JSONParserConfigurationTest {
|
|||||||
je.getMessage());
|
je.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputObject_testStrictModeTrue_JSONObjectUsingJSONTokener_shouldThrowJSONException() {
|
||||||
|
JSONException exception = assertThrows(JSONException.class, () -> {
|
||||||
|
new JSONObject(new JSONTokener("{\"key\":\"value\"} invalid trailing text"), new JSONParserConfiguration().withStrictMode(true));
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEquals("Strict mode error: Unparsed characters found at end of input text at 17 [character 18 line 1]", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputObject_testStrictModeTrue_JSONObjectUsingString_shouldThrowJSONException() {
|
||||||
|
JSONException exception = assertThrows(JSONException.class, () -> {
|
||||||
|
new JSONObject("{\"key\":\"value\"} invalid trailing text", new JSONParserConfiguration().withStrictMode(true));
|
||||||
|
});
|
||||||
|
assertEquals("Strict mode error: Unparsed characters found at end of input text at 17 [character 18 line 1]", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputObject_testStrictModeTrue_JSONArrayUsingJSONTokener_shouldThrowJSONException() {
|
||||||
|
JSONException exception = assertThrows(JSONException.class, () -> {
|
||||||
|
new JSONArray(new JSONTokener("[\"value\"] invalid trailing text"), new JSONParserConfiguration().withStrictMode(true));
|
||||||
|
});
|
||||||
|
|
||||||
|
assertEquals("Strict mode error: Unparsed characters found at end of input text at 11 [character 12 line 1]", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInvalidInputObject_testStrictModeTrue_JSONArrayUsingString_shouldThrowJSONException() {
|
||||||
|
JSONException exception = assertThrows(JSONException.class, () -> {
|
||||||
|
new JSONArray("[\"value\"] invalid trailing text", new JSONParserConfiguration().withStrictMode(true));
|
||||||
|
});
|
||||||
|
assertEquals("Strict mode error: Unparsed characters found at end of input text at 11 [character 12 line 1]", exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method contains short but focused use-case samples and is exclusively used to test strictMode unit tests in
|
* This method contains short but focused use-case samples and is exclusively used to test strictMode unit tests in
|
||||||
* this class.
|
* this class.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user