FactoryLocator { @SuppressWarnings("unchecked") public static <T> Factory<T> getFactory(Class<T> clazz) { try { Class<? extends Factory<T>> factoryClass = (Class<? extends Factory<T>>) Class.forName(clazz.getName() + "__Factory"); return factoryClass.newInstance(); } catch (Exception e) { throw new NoFactoryFoundException(clazz, e); } } private  FactoryLocator(); @SuppressWarnings("unchecked") static Factory<T> getFactory(Class<T> clazz);  }
@Test public void testGetFactory_shouldFindTheFactoryForFoo_whenTheFactoryIsGenerated() { FactoryLocator.getFactory(Foo.class); }
@Test(expected = NoFactoryFoundException.class) public void testGetFactory_shouldThrowAnException_whenTheFActoryIsNotGenerated() { FactoryLocator.getFactory(Qurtz.class); fail("Should throw an exception"); }