CompositeService extends AbstractService { protected boolean addIfService(Object object) { if (object instanceof Service) { addService((Service) object); return true; } else { return false; } } CompositeService(String name); List<Service> getServices();  }
@Test (timeout = 10000) public void testAddIfService() { CompositeService testService = new CompositeService("TestService") { Service service; @Override public void serviceInit(Configuration conf) { Integer notAService = new Integer(0); assertFalse("Added an integer as a service", addIfService(notAService)); service = new AbstractService("Service") {}; assertTrue("Unable to add a service", addIfService(service)); } }; testService.init(new Configuration()); assertEquals("Incorrect number of services", 1, testService.getServices().size()); }
@Test (timeout = 1000) public void testAddIfService() { CompositeService testService = new CompositeService("TestService") { Service service; @Override public void serviceInit(Configuration conf) { Integer notAService = new Integer(0); assertFalse("Added an integer as a service", addIfService(notAService)); service = new AbstractService("Service") {}; assertTrue("Unable to add a service", addIfService(service)); } }; testService.init(new Configuration()); assertEquals("Incorrect number of services", 1, testService.getServices().size()); }