Services { public static void run(Service service, String... args) throws IOException, InterruptedException { try (Service.Instance instance = service.start(args)) { LOG.info("Started service '{}'", service.getServiceName()); instance.waitForShutdown(); LOG.info("Stopping service '{}'", service.getServiceName()); } } private  Services(); static Service.Builder usingName(String serviceName); static void run(Service service, String... args); static final String INJECT_SERVICE_NAME; static final String INJECT_UNPROCESSED_ARGS; }
@Test public void testRun() throws Exception { String[] args = new String[]{"a", "b", "c"}; Service service = mock(Service.class); Service.Instance instance = mock(Service.Instance.class); when(service.start(args)).thenReturn(instance); Services.run(service, args); InOrder inOrder = inOrder(service, instance); inOrder.verify(service, times(1)).start(args); inOrder.verify(instance, times(1)).waitForShutdown(); inOrder.verify(instance, atLeastOnce()).close(); }