ConfigurableIngestTopology { IComponent buildComponent(String componentClassName, Configuration conf) throws ConfigurationException { try { Class component = Class.forName(componentClassName); IComponent instance = (IComponent) component.newInstance(); if (instance instanceof Configurable) { Configurable configurable = (Configurable) instance; configurable.configure(conf); } return instance; } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { logger.error("Unable to instantiate component: {}", componentClassName); throw new ConfigurationException(e); } }  static void main(String[] args);  }
@Test public void testBuildComponent( @Injectable Configuration conf) throws Exception { new Expectations(TestClassIComponent.class) {{ new TestClassIComponent(); }}; assertNotNull(topology.buildComponent(TestClassIComponent.class.getName(), conf)); }
@Test public void testBuildComponentException(@Injectable Configuration conf) throws Exception { thrown.expect(ConfigurationException.class); topology.buildComponent("InvalidClass", conf); }