Exemplo n.º 1
0
 private static void assertParseException(int offset, String message, final String json) {
   ParseException exception =
       assertException(
           ParseException.class,
           new Runnable() {
             public void run() {
               parse(json);
             }
           });
   assertEquals(offset, exception.getOffset());
   assertThat(exception.getMessage(), StringStartsWith.startsWith(message + " at"));
 }
Exemplo n.º 2
0
 private static void assertParseException(int offset, int line, int column, final String json) {
   ParseException exception =
       assertException(
           ParseException.class,
           new Runnable() {
             public void run() {
               parse(json);
             }
           });
   assertEquals("offset", offset, exception.getOffset());
   assertEquals("line", line, exception.getLine());
   assertEquals("column", column, exception.getColumn());
 }
Exemplo n.º 3
0
  @Test
  public void parse_rejectsEmptyReader() {
    ParseException exception =
        assertException(
            ParseException.class,
            new Runnable() {
              public void run() {
                try {
                  new JsonParser(new StringReader("")).parse();
                } catch (IOException exception) {
                  throw new RuntimeException(exception);
                }
              }
            });

    assertEquals(0, exception.getOffset());
    assertThat(exception.getMessage(), StringStartsWith.startsWith("Unexpected end of input at"));
  }
Exemplo n.º 4
0
  @Test
  public void parse_handlesPositionsCorrectlyWhenInputExceedsBufferSize() {
    final String input = "{\n  \"a\": 23,\n  \"b\": 42,\n}";

    ParseException exception =
        assertException(
            ParseException.class,
            new Runnable() {
              public void run() {
                try {
                  new JsonParser(new StringReader(input), 3).parse();
                } catch (IOException e) {
                }
              }
            });

    assertEquals(4, exception.getLine());
    assertEquals(0, exception.getColumn());
    assertEquals(24, exception.getOffset());
  }