DatabaseConnector { public void removeOutdatedVersionsFromBlacklistentry() { List<Long> blacklistversions = jdbcTemplate.queryForList("SELECT DISTINCT BLACKLISTVERSION FROM BLACKLISTENTRY", Long.TYPE); if (blacklistversions.size() > 1) { Long currentBlacklistversion = Collections.max(blacklistversions); int rowsAffected = jdbcTemplate.update("DELETE FROM BLACKLISTENTRY WHERE BLACKLISTVERSION <> ?", currentBlacklistversion); log.info("Deleted {} entries with outdated Blacklist versions from Blacklistentry", rowsAffected); } else { log.info("No entries with outdated Blacklist versions found."); } } DatabaseConnector(JdbcTemplate jdbcTemplate); List<byte[]> getTerminalsFromTerminalpermission(); void removeOutdatedSectorIDsFromBlacklistentry(); void removeOutdatedVersionsFromBlacklistentry(); boolean checkPrimaryKey(); boolean performMigrationWithoutData(); boolean performMigrationWithData();  }
@Test public void testRemoveOutdatedBlacklistVersions() { assertThat("The initial database must contain 5 entries", getNumberOfRows(), is(5)); connector.removeOutdatedVersionsFromBlacklistentry(); assertThat("No current versions should be deleted", getNumberOfRows(), is(5)); for ( int i = 0 ; i < 10 ; i++ ) { addEntryToBlacklistentry(Base64.getEncoder().encodeToString("XXX".getBytes(StandardCharsets.UTF_8)), UUID.randomUUID().toString(), "1000"); } assertThat("There must be 15 entries", getNumberOfRows(), is(15)); connector.removeOutdatedVersionsFromBlacklistentry(); assertThat("The 10 outdated entries should be deleted", getNumberOfRows(), is(5)); List<Long> expected = Arrays.asList(1337L); assertThat("Only the recent blacklist version should be present", getUniqueBlacklistVersions(), Matchers.containsInAnyOrder(expected.toArray())); }