ServiceObjectFactory { public static <T> List<T> createServiceObjects(String... pDescriptorPaths) { try { ServiceEntry.initDefaultOrder(); TreeMap<ServiceEntry,T> extractorMap = new TreeMap<ServiceEntry,T>(); for (String descriptor : pDescriptorPaths) { readServiceDefinitions(extractorMap, descriptor); } ArrayList<T> ret = new ArrayList<T>(); for (T service : extractorMap.values()) { ret.add(service); } return ret; } finally { ServiceEntry.removeDefaultOrder(); } } private  ServiceObjectFactory(); static List<T> createServiceObjects(String... pDescriptorPaths);  }
@Test public void testOrder() { List<TestService> services = ServiceObjectFactory.createServiceObjects("service/test-services-default", "service/test-services"); String[] orderExpected = new String[] { "three", "two", "five", "one"}; assertEquals(services.size(), 4); Iterator<TestService> it = services.iterator(); for (String val : orderExpected) { assertEquals(it.next().getName(),val); } }
@Test(expectedExceptions = IllegalStateException.class,expectedExceptionsMessageRegExp = ".*bla\\.blub\\.NotExist.*") public void errorHandling() { List<TestService> service = ServiceObjectFactory.createServiceObjects("service/error-services"); }
@Test(expectedExceptions = ClassCastException.class) public void classCastException() { List<String> services = ServiceObjectFactory.createServiceObjects("service/test-services"); String bla = services.get(0); }