@Test
public void testRemoveOldPersistentTokens() {

    User admin = userRepository.findOneByLogin("admin").get();
    int existingCount = persistentTokenRepository.findByUser(admin).size();
    generateUserToken(admin, "1111-1111", new LocalDate());
    LocalDate now = new LocalDate();
    generateUserToken(admin, "2222-2222", now.minusDays(32));
    assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 2);
    userService.removeOldPersistentTokens();
    assertThat(persistentTokenRepository.findByUser(admin)).hasSize(existingCount + 1);
}