ScriptHandlerFactory { public ScriptHandler getHandler(FileEntry fileEntry) { for (ScriptHandler handler : scriptHandlers) { if (handler.canHandle(fileEntry)) { return handler; } } throw processException("no matching handler for " + fileEntry.getPath()); }  @PostConstruct void init(); ScriptHandler getHandler(FileEntry fileEntry); ScriptHandler getHandler(String key);  }
@Test public void testFactoryCreation() { FileEntry fileEntry = new FileEntry(); fileEntry.setPath("/hello/world.groovy"); fileEntry.setCreatedUser(getTestUser()); assertThat(factory.getHandler(fileEntry)).isInstanceOf(GroovyScriptHandler.class); fileEntry.setPath("/hello/world.py"); assertThat(factory.getHandler(fileEntry)).isInstanceOf(JythonScriptHandler.class); }