Assert.assertTrue("Cache should have been used this time!", parser.isHitCache());
}
@Test
public void testQueryForJSONArray() throws Exception {
JSONParser parser = new JSONParser();
parser.parseJSON("{\"test\" : [\"1\", \"2\", \"3\"]}");
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
Assert.assertEquals("1", parser.getJSONArray("test").get(0));
parser = new JSONParser();
parser.parseJSON("{\"test\" : [1,2,3]}");
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
Assert.assertFalse(parser.isHitCache());
Assert.assertEquals(2, parser.getJSONArray("test").get(1));
Assert.assertTrue(parser.isHitCache());
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
Assert.assertEquals(2, parser.getJSONArray("test").get(1));
Assert.assertTrue(parser.isHitCache());
parser = new JSONParser();
parser.parseJSON("{\"test\" : [{second_level: \"3\"}, {\"third_level\" : 2}]}");
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
Assert.assertTrue(parser.getJSONArray("test").get(0) instanceof JSONObject);
Assert.assertEquals(2, parser.getInt("test[1].third_level"));
Assert.assertEquals("3", parser.getString("test[0].second_level"));
parser = new JSONParser();
parser.parseJSON("{\"test\" : [{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{1:1},{2:3},{4:5}]}");
Assert.assertTrue(parser.getJSONArray("test") instanceof JSONArray);
Assert.assertEquals(5, parser.getInt("test[10].4"));
}