### Question:
SqlTokenizer { public String nextClause() { String toReturn = null; String nextToken; while ((nextToken = next()) != null) { if (keywords.contains(nextToken.toLowerCase())) { if (clause.length() > 0) { toReturn = clause.toString(); clause = new StringBuilder(nextToken); return toReturn; } } clause.append(nextToken); } if (clause.length() > 0) { toReturn = clause.toString(); clause = new StringBuilder(); } return toReturn; } SqlTokenizer(String chars); String nextClause(); String next();  }### Answer:
@Test public void testClauses() throws Exception { String[][] tests = new String[][]{ { "select * from `order details` where \"id\" in (select * from some other table) and x >= 500", "select * |from `order details` |where \"id\" in (select * from some other table) and x >= 500" }, { "SELECT * FROM (SELECT *, 'Threatened' as 'Victim' FROM Entry WHERE threatened = true UNION SELECT *, 'Tortured' as 'Victim' FROM Entry WHERE tortured = true UNION SELECT *, 'Taken Captive' as 'Victim' FROM Entry WHERE captive = true )as t", "SELECT * |FROM (SELECT *, 'Threatened' as 'Victim' FROM Entry WHERE threatened = true UNION SELECT *, 'Tortured' as 'Victim' FROM Entry WHERE tortured = true UNION SELECT *, 'Taken Captive' as 'Victim' FROM Entry WHERE captive = true )as t" } }; for (String[] test : tests) { String input = test[0]; List<String> expected = Arrays.asList(test[1].split("\\|")); String next; List<String> actual = new ArrayList<>(); SqlTokenizer tok = new SqlTokenizer(input); while ((next = tok.nextClause()) != null) { actual.add(next); } if (!Utils.testCompare(expected.toString(), actual.toString())) fail(); } }