MigrationRepository { public List<DbMigration> getMigrationsSinceVersion(int version) { List<DbMigration> dbMigrations = new ArrayList<>(); migrationScripts.stream().filter(script -> script.getVersion() > version).forEach(script -> { String content = loadScriptContent(script); String updatedContent = scriptFilter.filter(content); dbMigrations.add(new DbMigration(script.getScriptName(), script.getVersion(), updatedContent)); }); return dbMigrations; } MigrationRepository();  MigrationRepository(String scriptPath);  MigrationRepository(String scriptPath, ScriptCollector scriptCollector);  MigrationRepository(String scriptPath, ScriptCollector scriptCollector, ScannerRegistry scannerRegistry); void setScriptFilter(ScriptFilter scriptFilter); int getLatestVersion(); List<DbMigration> getMigrationsSinceVersion(int version); static final String DEFAULT_SCRIPT_PATH; static final String SCRIPT_EXTENSION; static final String SCRIPT_ENCODING; static final String VERSION_NAME_DELIMITER; static final String SINGLE_LINE_COMMENT_PATTERN; }
@Test public void shouldReturnOneScriptWhenRequestForAllScriptsSinceVersionTwoGiven() { List<DbMigration> scripts = migrationRepository.getMigrationsSinceVersion(2); assertThat(scripts.size(), is(equalTo(1))); assertThat(scripts.get(0).getVersion(), is(equalTo(3))); }
@Test public void shouldReturnTwoScriptsWhenRequestForAllScriptsSinceVersionOneGiven() { List<DbMigration> scripts = migrationRepository.getMigrationsSinceVersion(1); assertThat(scripts.size(), is(equalTo(2))); assertThat(scripts.get(0).getVersion(), is(equalTo(2))); assertThat(scripts.get(1).getVersion(), is(equalTo(3))); assertThat(scripts.get(0).getMigrationScript().isEmpty(), is(false)); assertThat(scripts.get(1).getMigrationScript().isEmpty(), is(false)); }
@Test public void shouldIgnoreComments() { List<DbMigration> scripts = migrationRepository.getMigrationsSinceVersion(1); assertThat(scripts.get(0).getMigrationScript().contains("--"), is(false)); assertThat(scripts.get(0).getMigrationScript().contains(" }