RunHandlerFactory { public static RunHandler getController( final RunHandler.Context context, final RunHandlerConfig config){ final String name = "no.sesat.search.run.handler." + config.getClass().getAnnotation(Controller.class).value(); try{ final SiteClassLoaderFactory.Context ctlContext = ContextWrapper.wrap( SiteClassLoaderFactory.Context.class, new BaseContext() { public Spi getSpi() { return Spi.RUN_HANDLER_CONTROL; } }, context ); final ClassLoader ctlLoader = SiteClassLoaderFactory.instanceOf(ctlContext).getClassLoader(); @SuppressWarnings("unchecked") final Class<? extends RunHandler> cls = (Class<? extends RunHandler>)ctlLoader.loadClass(name); final Constructor<? extends RunHandler> constructor = cls.getConstructor(RunHandlerConfig.class); return constructor.newInstance(config); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException(ex); } catch (NoSuchMethodException ex) { throw new IllegalArgumentException(ex); } catch (InvocationTargetException ex) { throw new IllegalArgumentException(ex); } catch (InstantiationException ex) { throw new IllegalArgumentException(ex); } catch (IllegalAccessException ex) { throw new IllegalArgumentException(ex); } } private  RunHandlerFactory(); static RunHandler getController(
            final RunHandler.Context context,
            final RunHandlerConfig config);  }
@Test final public void testGetController() throws Exception { final DataModelFactory factory = DataModelFactory.instanceOf(new DataModelFactory.Context() { public Site getSite() { return Site.DEFAULT; } public PropertiesLoader newPropertiesLoader(final SiteContext siteCxt, final String resource, final Properties properties) { return TestResourceLoader.newPropertiesLoader(siteCxt, resource, properties); } }); final DataModel datamodel = factory.instantiate(); final Site site = getTestingSite(); final SiteConfiguration.Context cxt = new SiteConfiguration.Context() { public Site getSite() { return site; } public PropertiesLoader newPropertiesLoader( final SiteContext siteContext, final String resource, final Properties properties) { return TestResourceLoader.newPropertiesLoader(siteContext, resource, properties); } }; final SiteConfiguration siteConfig = SiteConfiguration.instanceOf(cxt); final SiteDataObject siteDO = factory.instantiate( SiteDataObject.class, datamodel, new DataObject.Property("site", site), new DataObject.Property("siteConfiguration", siteConfig)); datamodel.setSite(siteDO); final RunHandler.Context context = new RunHandler.Context() { public DataModel getDataModel() { return datamodel; } public PropertiesLoader newPropertiesLoader(SiteContext siteCxt, String resource, Properties properties) { return TestResourceLoader.newPropertiesLoader(siteCxt, resource, properties); } public Site getSite() { return datamodel.getSite().getSite(); } public DocumentLoader newDocumentLoader(SiteContext siteCxt, String resource, DocumentBuilder builder) { return TestResourceLoader.newDocumentLoader(siteCxt, resource, builder); } public BytecodeLoader newBytecodeLoader(SiteContext siteContext, String className, String jarFileName) { return TestResourceLoader.newBytecodeLoader(siteContext, className, className); } }; final RunHandlerConfig config = new TestRunHandlerConfig(); final RunHandler rh = RunHandlerFactory.getController(context, config); assert rh != null; }