### Question:
MigrationOnStartupListener implements ApplicationListener<ApplicationStartupEvent>, ApplicationContextAware, InitializingBean { @Override public void onApplicationEvent(ApplicationStartupEvent applicationStartupEvent) { if (automaticMigration) { LOG.debug("Starting automatic migration after startup."); fireflyService.migrate(); } else { LOG.debug("Skipping automatic migration. To change this set the parameter 'firefly.migrationOnStartup' to true."); fireflyService.simulate(); } } @Autowired  MigrationOnStartupListener(FireflyService fireflyService,
                                      @Value("${firefly.migrationOnStartup:false}") boolean automaticMigration); @Override void onApplicationEvent(ApplicationStartupEvent applicationStartupEvent); @Override void afterPropertiesSet(); @Override void setApplicationContext(ApplicationContext applicationContext);  }### Answer:
@Test public void shouldStartAutomaticMigration() { MigrationOnStartupListener listener = new MigrationOnStartupListener( fireflyService, true); listener.onApplicationEvent(new ApplicationStartupEvent()); verify(fireflyService).migrate(); }
@Test public void shouldRunSimulation() { MigrationOnStartupListener listener = new MigrationOnStartupListener( fireflyService, false ); listener.onApplicationEvent(new ApplicationStartupEvent()); verify(fireflyService).simulate(); }