GroovyMavenProjectScriptHandler extends GroovyScriptHandler implements ProjectHandler { @Override public boolean canHandle(FileEntry fileEntry) { String path = fileEntry.getPath(); if (!FilenameUtils.isExtension(path, "groovy")) { return false; } if (!isGroovyMavenPath(path)) { return false; } if (isGitHubFileEntry(fileEntry)) { return StringUtils.equals(fileEntry.getProperties().get("type"), "groovy-maven"); } else { if (fileEntry.getCreatedUser() == null) { return false; } return getFileEntryRepository().hasOne(fileEntry.getCreatedUser(), getBasePath(path) + "pom.xml"); } } GroovyMavenProjectScriptHandler(); @Override boolean canHandle(FileEntry fileEntry); @Override Integer displayOrder(); @Override List<FileEntry> getLibAndResourceEntries(User user, FileEntry scriptEntry, long revision); @Override boolean prepareScriptEnv(User user, String path, String fileName, String name, // LF
	                                String url, boolean createLib, String scriptContent); @Override String getBasePath(String path); @Override String getScriptExecutePath(String path); @Override FileEntry getDefaultQuickTestFilePath(String path); String getGroovyMavenPath(String path); boolean isGroovyMavenPath(String path);  }
@Test public void testHandlerMatching() { GroovyMavenProjectScriptHandler handler = new GroovyMavenProjectScriptHandler(); User user = new User("my", "my", "password", Role.ADMIN); FileEntryRepository serviceMock = mock(FileEntryRepository.class); when(serviceMock.hasOne(user, "/hello/world/pom.xml")).thenReturn(true); setField(handler, "fileEntryRepository", serviceMock); FileEntry entry = new FileEntry(); entry.setPath("/hello/world/src/main/java/wow/Global.groovy"); entry.setCreatedUser(user); assertThat(handler.canHandle(entry)).isTrue(); entry.setPath("/hello/world/src/main/wow/Global.groovy"); assertThat(handler.canHandle(entry)).isFalse(); entry.setPath("/hello/world/src/main/java/Global.py"); assertThat(handler.canHandle(entry)).isFalse(); when(serviceMock.hasOne(user, "/hello/world/pom.xml")).thenReturn(false); entry.setPath("/hello/world/src/main/java/Global.groovy"); assertThat(handler.canHandle(entry)).isFalse(); }