@Test public void runWithServiceWithNOnStoppedStatus() { Stream.of(Status.values()) .filter(s -> s != Status.STOPPED) .forEach(s -> { when(service.status()).thenReturn(s); serviceContainer.run(); }); verify(service, times(Status.values().length - 1)).status(); }
@Override public void run() { LOGGER.trace("Check status {}", service); Status status = service.status(); LOGGER.trace("{} Status is {}", service, status); if (status == Service.Status.STOPPED) { LOGGER.warn("Service {} is stopped, attempting to start it.", service); try { LOGGER.debug("Starting service {}", service); service.start(); LOGGER.debug("Started service {}", service); } catch (Throwable ex) { LOGGER.trace(null, ex); LOGGER.error( "Exception thrown : {} While starting service {}", Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(), service); } } }
ServiceContainer implements Runnable { @Override public void run() { LOGGER.trace("Check status {}", service); Status status = service.status(); LOGGER.trace("{} Status is {}", service, status); if (status == Service.Status.STOPPED) { LOGGER.warn("Service {} is stopped, attempting to start it.", service); try { LOGGER.debug("Starting service {}", service); service.start(); LOGGER.debug("Started service {}", service); } catch (Throwable ex) { LOGGER.trace(null, ex); LOGGER.error( "Exception thrown : {} While starting service {}", Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(), service); } } } }
ServiceContainer implements Runnable { @Override public void run() { LOGGER.trace("Check status {}", service); Status status = service.status(); LOGGER.trace("{} Status is {}", service, status); if (status == Service.Status.STOPPED) { LOGGER.warn("Service {} is stopped, attempting to start it.", service); try { LOGGER.debug("Starting service {}", service); service.start(); LOGGER.debug("Started service {}", service); } catch (Throwable ex) { LOGGER.trace(null, ex); LOGGER.error( "Exception thrown : {} While starting service {}", Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(), service); } } } ServiceContainer(final Service service);  ServiceContainer(
            final Service service,
            final ScheduledExecutorService executorService,
            final long initialDelay,
            final long period); }
ServiceContainer implements Runnable { @Override public void run() { LOGGER.trace("Check status {}", service); Status status = service.status(); LOGGER.trace("{} Status is {}", service, status); if (status == Service.Status.STOPPED) { LOGGER.warn("Service {} is stopped, attempting to start it.", service); try { LOGGER.debug("Starting service {}", service); service.start(); LOGGER.debug("Started service {}", service); } catch (Throwable ex) { LOGGER.trace(null, ex); LOGGER.error( "Exception thrown : {} While starting service {}", Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(), service); } } } ServiceContainer(final Service service);  ServiceContainer(
            final Service service,
            final ScheduledExecutorService executorService,
            final long initialDelay,
            final long period); @PostConstruct void start(); @PreDestroy void stop(); @Override void run(); }
ServiceContainer implements Runnable { @Override public void run() { LOGGER.trace("Check status {}", service); Status status = service.status(); LOGGER.trace("{} Status is {}", service, status); if (status == Service.Status.STOPPED) { LOGGER.warn("Service {} is stopped, attempting to start it.", service); try { LOGGER.debug("Starting service {}", service); service.start(); LOGGER.debug("Started service {}", service); } catch (Throwable ex) { LOGGER.trace(null, ex); LOGGER.error( "Exception thrown : {} While starting service {}", Optional.ofNullable(ex.getCause()).orElse(ex).getMessage(), service); } } } ServiceContainer(final Service service);  ServiceContainer(
            final Service service,
            final ScheduledExecutorService executorService,
            final long initialDelay,
            final long period); @PostConstruct void start(); @PreDestroy void stop(); @Override void run();  }