### Question:
ScriptReader { public String readSql() { if (endOfFile) { return null; } try { if (reader == null) { reader = createBufferedReader(); } SqlBuilder builder = new SqlBuilder(); readLineLoop: for (; ; ) { if (endOfLine) { lineCount++; tokenizer.addLine(reader.readLine()); builder.notifyLineChanged(); } for (; ; ) { builder.build(tokenizer.nextToken(), tokenizer.getToken()); if (builder.isTokenRequired()) { continue; } else if (builder.isLineRequired()) { continue readLineLoop; } else if (builder.isCompleted()) { return builder.getSql(); } assertUnreachable(); } } } catch (IOException e) { throw new JdbcException(Message.DOMA2078, e, query.getScriptFilePath(), e); } } ScriptReader(ScriptQuery query); String readSql(); int getLineNumber(); void close();  }### Answer:
@Test public void testReadSql_delimiter() { ScriptReader reader = new ScriptReader(query) { @Override protected BufferedReader createBufferedReader() { String script = "aaa;\nbbb\ngo\nccc\nddd\n"; StringReader reader = new StringReader(script); return new BufferedReader(reader); } }; assertEquals("aaa", reader.readSql()); assertEquals("bbb", reader.readSql()); assertEquals("ccc ddd", reader.readSql()); assertNull(reader.readSql()); }
@Test public void testReadSql_delimiterInLine() { ScriptReader reader = new ScriptReader(query) { @Override protected BufferedReader createBufferedReader() { StringReader reader = new StringReader("aaa; bbb; ccc;\n"); return new BufferedReader(reader); } }; assertEquals("aaa", reader.readSql()); assertEquals("bbb", reader.readSql()); assertEquals("ccc", reader.readSql()); assertNull(reader.readSql()); }
@Test public void testReadSql_sqlBlock() { ScriptReader reader = new ScriptReader(query) { @Override protected BufferedReader createBufferedReader() { String script = "begin aaa; end\n" + "go\n"; StringReader reader = new StringReader(script); return new BufferedReader(reader); } }; assertEquals("begin aaa; end", reader.readSql()); assertNull(reader.readSql()); }
@Test public void testReadSql_sqlBlock_createTrigger() { ScriptReader reader = new ScriptReader(query) { @Override protected BufferedReader createBufferedReader() { String script = "create trigger hoge begin aaa; end\n" + "go\n"; StringReader reader = new StringReader(script); return new BufferedReader(reader); } }; assertEquals("create trigger hoge begin aaa; end", reader.readSql()); assertNull(reader.readSql()); }
@Test public void testReadSql_notSqlBlock() { ScriptReader reader = new ScriptReader(query) { @Override protected BufferedReader createBufferedReader() { String script = "start aaa; end\n" + "go\n"; StringReader reader = new StringReader(script); return new BufferedReader(reader); } }; assertEquals("start aaa", reader.readSql()); assertEquals("end", reader.readSql()); }
@Test public void testReadSql_commentBlock() { ScriptReader reader = new ScriptReader(query) { @Override protected BufferedReader createBufferedReader() { String script = "select 1 ; select 2;"; StringReader reader = new StringReader(script); return new BufferedReader(reader); } }; assertEquals("select 1", reader.readSql()); assertEquals("select 2", reader.readSql()); assertNull(reader.readSql()); }