JsonParser { public void parse(Reader reader) throws JsonException { pushbackReader = new PushbackReader(reader); eventHandler.reset(); stack.clear(); char c; while ((c = next()) != END_OF_STREAM) { if (c == '{') { readObject(); } else if (c == '[') { readArray(); } else { throw new JsonException(String.format("Syntax error. Unexpected '%s'. Must be '{'.", c)); } c = assertNextIs(",]}"); if (c != END_OF_STREAM) { pushBack(c); } } if (!stack.isEmpty()) { throw new JsonException("Syntax error. Missing one or more close bracket(s)."); } } JsonParser(); protected  JsonParser(JsonHandler eventHandler); void parse(Reader reader); void parse(InputStream stream); JsonValue getJsonObject();  }
@Test(expected = JsonException.class) public void failsWhenMultiLineCommentIsNotEndedProperly() throws Exception { String jsonString = "{\"foo\":" + "/* comment\n" + " continue comment\n" + "\"bar\"}"; parser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes()))); }
@UseDataProvider("invalidJson") @Test(expected = JsonException.class) public void failsParseInvalidJson(String jsonString) throws Exception { parser.parse(new InputStreamReader(new ByteArrayInputStream(jsonString.getBytes()))); }