DatabaseConnector { public void removeOutdatedSectorIDsFromBlacklistentry() { int rowsAffected = jdbcTemplate.update("DELETE FROM BLACKLISTENTRY WHERE SECTORID <> ?", Base64.getEncoder() .encodeToString(getTerminalsFromTerminalpermission().get(0))); log.info("Deleted {} entries with outdated sectorIDs from Blacklistentry", rowsAffected); } DatabaseConnector(JdbcTemplate jdbcTemplate); List<byte[]> getTerminalsFromTerminalpermission(); void removeOutdatedSectorIDsFromBlacklistentry(); void removeOutdatedVersionsFromBlacklistentry(); boolean checkPrimaryKey(); boolean performMigrationWithoutData(); boolean performMigrationWithData();  }
@Test public void testRemoveOutdatedSectorIDs() { assertThat("The initial database must contain 5 entries", getNumberOfRows(), is(5)); connector.removeOutdatedSectorIDsFromBlacklistentry(); assertThat("No entry 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(), "1338"); } assertThat("There should be 15 entries", getNumberOfRows(), is(15)); assertThat("There should be two different SectorIDs", getUniqueSectorIDs().size(), is(2)); connector.removeOutdatedSectorIDsFromBlacklistentry(); assertThat("The 10 unused entries should be deleted", getNumberOfRows(), is(5)); assertThat("There should be only the original SectorID", getUniqueSectorIDs(), Matchers.containsInAnyOrder(Base64.getEncoder() .encodeToString("AAA".getBytes(StandardCharsets.UTF_8)))); }