DatabaseSchemaVersionManager implements AppliedChangesProvider { public List<Long> getAppliedChanges() { try { ResultSet rs = queryExecuter.executeQuery( "SELECT change_number FROM " + changeLogTableName + " ORDER BY change_number"); List<Long> changeNumbers = new ArrayList<Long>(); while (rs.next()) { changeNumbers.add(rs.getLong(1)); } rs.close(); return changeNumbers; } catch (SQLException e) { throw new SchemaVersionTrackingException("Could not retrieve change log from database because: " + e.getMessage(), e); } } DatabaseSchemaVersionManager(QueryExecuter queryExecuter, String changeLogTableName); List<Long> getAppliedChanges(); String getChangelogDeleteSql(ChangeScript script); void recordScriptApplied(ChangeScript script); void setTimeProvider(CurrentTimeProvider timeProvider);  }
@Test public void shouldUseQueryExecuterToReadInformationFromTheChangelogTable() throws Exception { when(expectedResultSet.next()).thenReturn(true, true, true, false); when(expectedResultSet.getLong(1)).thenReturn(5L, 9L, 12L); final List<Long> numbers = schemaVersionManager.getAppliedChanges(); assertThat(numbers, hasItems(5L, 9L, 12L)); }
@Test public void shouldGetAppliedChangesFromSpecifiedChangelogTableName() throws SQLException { DatabaseSchemaVersionManager schemaVersionManagerWithDifferentTableName = new DatabaseSchemaVersionManager(queryExecuter, "user_specified_changelog"); schemaVersionManagerWithDifferentTableName.getAppliedChanges(); verify(queryExecuter).executeQuery(startsWith("SELECT change_number FROM user_specified_changelog ")); }