ResourceManager implements ServerListener { @Override public void handle(final ServerEvent event) { if (!eventFilter.contains(event.getType())) { logger.trace("Unhandled event: {}", event); return; } final Collection<File> files = nvl((Collection<File>) event.getNewData(), EMPTY_LIST); final Optional<Resource> cachedResourceOpt = files.stream().map(file -> { final String path = getCanonicalForm(file.getAbsolutePath()); final String projectPath = getCanonicalForm(project.getPath().toAbsolutePath().toString()); final Path relativePath = Paths.get(projectPath).relativize(Paths.get(path)); logger.trace("Project path: {}, Path: {}, Relative path: {}", projectPath, path, relativePath); final String relativePathStr = relativePath.toString(); logger.debug("Relative path: {}", relativePath); final String canonicalPath = getCanonicalForm(relativePathStr); logger.trace("Project relative path: {}", canonicalPath); return cache.get(canonicalPath); }).filter(Objects::nonNull).findFirst(); if (cachedResourceOpt.isPresent()) { final Resource cached = cachedResourceOpt.get(); logger.info("{} changed: {}", cached, event.getType()); fireEvent(new ResourceChangeEvent(cached)); } }  void addResourceChangeListener(final ResourceChangeListener listener); void removeResourceChangeListener(final ResourceChangeListener listener); synchronized Resource getResource(final String path); Resource getPackage(final String packageName); @Override void handle(final ServerEvent event);  }
@Test public void testHandle() { final ProjectFile projectFile = new ProjectFile(); final Project project = new Project(randomUUID().toString(), projectFile); final Server server = mock(Server.class); final ResourceManager resourceManager = new ResourceManager(project); final File changedFile = new File(project.getLocation() + "/" + randomUUID().toString()); final ServerEvent serverEvent = new ServerEvent(server, ANY_CHANGED, singletonList(changedFile)); resourceManager.handle(serverEvent); }