Sender implements AutoCloseable { @Override public void close() throws Exception { service.shutdown(); if (!service.awaitTermination(5, TimeUnit.MINUTES)) { throw new Exception("Timed out waiting for sender service to terminate"); } log.info("Shutdown sender"); } @Autowired  Sender(
      AsyncRoadClient<TestMessage> onrampClient,
      TestMessageContextManager contextManager,
      @Value("${messageHz}") long messageRate);   Sender(
      AsyncRoadClient<TestMessage> onrampClient,
      TestMessageContextManager contextManager,
      long messageRate,
      ScheduledExecutorService service); void start(); void worker(); @Override void close();  }
@Test public void close_shuts_down_service() throws Exception { new Sender(onrampClient, contextManager, 1L, service).close(); verify(service).shutdown(); }
@Test(expected = Exception.class) public void close_throws_if_service_doesnt_shutdown() throws Exception { when(service.awaitTermination(anyLong(), any())).thenReturn(false); new Sender(onrampClient, contextManager, 1L, service).close(); }