DirectToDbApplier implements ChangeScriptApplier { protected void applyChangeScript(ChangeScript script) { List<String> statements = splitter.split(script.getContent()); for (int i = 0; i < statements.size(); i++) { String statement = statements.get(i); try { if (statements.size() > 1) { System.err.println(" -> statement " + (i+1) + " of " + statements.size() + "..."); } queryExecuter.execute(statement); } catch (SQLException e) { throw new ChangeScriptFailedException(e, script, i+1, statement); } } } DirectToDbApplier(QueryExecuter queryExecuter, DatabaseSchemaVersionManager schemaVersionManager, QueryStatementSplitter splitter); void apply(List<ChangeScript> changeScript); void begin();  }
@Test public void shouldApplyChangeScriptBySplittingContentUsingTheSplitter() throws Exception { when(splitter.split("split; content")).thenReturn(Arrays.asList("split", "content")); applier.applyChangeScript(new StubChangeScript(1, "script", "split; content")); verify(queryExecuter).execute("split"); verify(queryExecuter).execute("content"); }
@Test public void shouldRethrowSqlExceptionsWithInformationAboutWhatStringFailed() throws Exception { when(splitter.split("split; content")).thenReturn(Arrays.asList("split", "content")); ChangeScript script = new StubChangeScript(1, "script", "split; content"); doThrow(new SQLException("dummy exception")).when(queryExecuter).execute("split"); try { applier.applyChangeScript(script); fail("exception expected"); } catch (ChangeScriptFailedException e) { assertThat(e.getExecutedSql(), is("split")); assertThat(e.getScript(), is(script)); } verify(queryExecuter, never()).execute("content"); }