### Question:
RegistrationApplicationListener implements InitializingBean, DisposableBean { @EventListener @Order(Ordered.LOWEST_PRECEDENCE) public void onClosedContext(ContextClosedEvent event) { if (event.getApplicationContext().getParent() == null || "bootstrap".equals(event.getApplicationContext().getParent().getId())) { stopRegisterTask(); if (autoDeregister) { registrator.deregister(); } } } RegistrationApplicationListener(ApplicationRegistrator registrator);   RegistrationApplicationListener(ApplicationRegistrator registrator, ThreadPoolTaskScheduler taskScheduler); @EventListener @Order(Ordered.LOWEST_PRECEDENCE) void onApplicationReady(ApplicationReadyEvent event); @EventListener @Order(Ordered.LOWEST_PRECEDENCE) void onClosedContext(ContextClosedEvent event); void startRegisterTask(); void stopRegisterTask(); void setAutoDeregister(boolean autoDeregister); void setAutoRegister(boolean autoRegister); void setRegisterPeriod(Duration registerPeriod); @Override void afterPropertiesSet(); @Override void destroy();  }### Answer:
@Test public void should_not_deregister_when_not_autoDeregister() { ApplicationRegistrator registrator = mock(ApplicationRegistrator.class); ThreadPoolTaskScheduler scheduler = mock(ThreadPoolTaskScheduler.class); RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler); listener.onClosedContext(new ContextClosedEvent(mock(WebApplicationContext.class))); verify(registrator, never()).deregister(); }