JsonFinder { protected List<Integer> countParenthesis(String string) { final List<Integer> openParenthesis = new ArrayList<>(string.length()); int currentValue = 0; boolean escaped = false; boolean inString = false; for (int i = 0; i < string.length(); i++) { final char c = string.charAt(i); if (c == '{' && !inString) { currentValue++; } else if (c == '}' && !inString) { currentValue--; } else if (!escaped && c == '"') { inString = !inString; } else { escaped = c == '\\' && !escaped; } openParenthesis.add(currentValue); } return openParenthesis; }  ArrayList<SubText> findJsonFragments(String string);  }
@Test(dataProvider = "testCountParenthesis") public void testCountParenthesis(String string, String result) throws Exception { final List<Integer> actual = underTest.countParenthesis(string); final String actualString = Joiner.on("").join(actual); Assert.assertEquals(actualString, result.replace(" ", ""),string); }