LevelsFactory { public Levels getGameLevels(FigureQueue playerQueue, String levels) { String className = LevelsFactory.class.getPackage().getName() + '.' + levels; try { Class<?> aClass = this.getClass().getClassLoader().loadClass(className); return (Levels) Reflection.constructor().withParameterTypes(PlayerFigures.class).in(aClass).newInstance(playerQueue); } catch (ClassNotFoundException e) { return throwRuntime(e); } }  Set<Class<? extends Levels>> getAllLevelsInPackage(); Levels getGameLevels(FigureQueue playerQueue, String levels);  }
@Test public void shouldLoadClass(){ Levels loaded = factory.getGameLevels(mock(PlayerFigures.class), "HardLevels"); assertEquals(HardLevels.class, loaded.getClass()); }