### Question:
StringUtils { public static String[] processMutliLineSQL(String multiLineSQL,boolean stripComments, boolean splitStatements, String endDelimiter) { String stripped = stripComments ? stripComments(multiLineSQL) : multiLineSQL; if (splitStatements) { return splitSQL(stripped, endDelimiter); } else { return new String[]{stripped}; } }  static String trimToEmpty(String string); static String trimToNull(String string); static String[] processMutliLineSQL(String multiLineSQL,boolean stripComments, boolean splitStatements, String endDelimiter); static String[] splitSQL(String multiLineSQL, String endDelimiter); static String stripComments(String multiLineSQL); static String join(String[] array, String delimiter); static String join(Collection<String> collection, String delimiter); static List<String> splitAndTrim(String s, String regex); static String repeat(String string, int times); static String join(Integer[] array, String delimiter); static String join(int[] array, String delimiter);  }### Answer:
@Test public void shouldStripComments() { String sql = "some sql"; String comment = "" ; String total = sql + comment + sql; String[] result = StringUtils.processMutliLineSQL(total,true, false, null); assertEquals(1,result.length); assertEquals(sql+sql,result[0]); }
@Test public void stripComments2() { String sql = "insert into test_table values(1, 'hello');\n" + "insert into test_table values(2, 'hello');\n" + "--insert into test_table values(3, 'hello');\n" + "insert into test_table values(4, 'hello');"; String[] result = StringUtils.processMutliLineSQL(sql, true, true, ";"); assertEquals(3, result.length); }
@Test public void shouldNotStripComments() { String sql = "some sql"; String comment = "" ; String total = sql + comment + sql; String[] result = StringUtils.processMutliLineSQL(total,false, false, null); assertEquals(1,result.length); assertEquals(total,result[0]); }
@Test public void multilineComment() { String sql = "\n" + "\n" + "Select * from Test;\n" + "Update Test set field = 1"; String[] result = StringUtils.processMutliLineSQL(sql,true, true, null); assertEquals(2,result.length); assertEquals("Select * from Test",result[0]); assertEquals("Update Test set field = 1",result[1]); }
@Test public void testSplitWithSemicolon() { StringBuilder sb = new StringBuilder(); sb.append("select * from simple_select_statement;\n"); sb.append("insert into table ( col ) values (' value with; semicolon ');"); String[] result = StringUtils.processMutliLineSQL(sb.toString(), true, true, null); assertEquals("Unexpected amount of statements returned",2, result.length); }
@Test public void commentRemoval() { String testString = "--\n" + "-- Create the blog table.\n" + "--\n" + "CREATE TABLE blog\n" + "(\n" + " ID NUMBER(15) NOT NULL\n" + ")"; String[] strings = StringUtils.processMutliLineSQL(testString, true, false, null); assertEquals(1, strings.length); assertTrue(strings[0].startsWith("CREATE TABLE blog")); }
@Test public void windowsDelimiter() { String sql = "\n" + "\n" + "Select * from Test;\n" + "Update Test set field = 1"; String[] result = StringUtils.processMutliLineSQL(sql,true, true, ";"); assertEquals(2,result.length); assertEquals("Select * from Test",result[0]); assertEquals("Update Test set field = 1",result[1]); }
@Test public void multipleComments() { String raw = "\n" + "create table sqlfilerollback (id int);\n" + "\n" + "\n" + "create table sqlfilerollback2 (id int);"; String[] strings = StringUtils.processMutliLineSQL(raw, true, true, null); assertEquals(2, strings.length); assertEquals("create table sqlfilerollback (id int)", strings[0]); assertEquals("create table sqlfilerollback2 (id int)", strings[1]); }