if (context.getPath().getFileName().toString().equals(LAST_MODIFIED_MARKER_FILE)) { markerFileModified = true; break;
if (context.getPath().getFileName().toString().equals(LAST_MODIFIED_MARKER_FILE)) { markerFileModified = true; break;
@Override public boolean doFilter(WatchEvent<?> object) { final WatchContext context = (WatchContext) object.context(); if (object.kind().equals(StandardWatchEventKind.ENTRY_MODIFY)) { if (shouldFilter(context.getOldPath())) { return true; } } else if (object.kind().equals(StandardWatchEventKind.ENTRY_CREATE)) { if (shouldFilter(context.getPath())) { return true; } } else if (object.kind().equals(StandardWatchEventKind.ENTRY_RENAME)) { if (shouldFilter(context.getOldPath())) { return true; } } else if (object.kind().equals(StandardWatchEventKind.ENTRY_DELETE)) { if (shouldFilter(context.getOldPath())) { return true; } } return false; }
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
@SuppressWarnings("unchecked") private WatchEvent<?> mockWatchEvent(WatchEvent.Kind kind, String originalPathURI, String newPathURI, String sessionId, String userId, String commitMessage) throws URISyntaxException { WatchEvent<?> event = mock(WatchEvent.class); when(event.kind()).thenReturn(kind); FileSystem fileSystem = mock(FileSystem.class); Set<String> supportedViews = new HashSet<>(); when(fileSystem.supportedFileAttributeViews()).thenReturn(supportedViews); WatchContext context = mock(WatchContext.class); when(context.getSessionId()).thenReturn(sessionId); when(context.getUser()).thenReturn(userId); when(context.getMessage()).thenReturn(commitMessage); Path oldPath = mock(Path.class); URI oldPathUri = new URI(originalPathURI); when(oldPath.toUri()).thenReturn(oldPathUri); when(oldPath.getFileSystem()).thenReturn(fileSystem); Path path = mock(Path.class); URI pathUri = new URI(newPathURI); when(path.toUri()).thenReturn(pathUri); when(path.getFileSystem()).thenReturn(fileSystem); when(context.getOldPath()).thenReturn(oldPath); when(context.getPath()).thenReturn(path); when(event.context()).thenReturn(context); return event; }
final Path path = (created) ? context.getPath() : context.getOldPath();
private Pair<Path, ResourceChange> buildChange(final WatchEvent<?> event) { final WatchContext context = (WatchContext) event.context(); final Path _affectedPath; final ResourceChange result; if (event.kind().equals(StandardWatchEventKind.ENTRY_MODIFY)) { _affectedPath = convert(context.getOldPath()); result = new ResourceUpdated(context.getMessage()); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_CREATE)) { _affectedPath = convert(context.getPath()); result = new ResourceAdded(context.getMessage()); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_RENAME)) { _affectedPath = convert(context.getOldPath()); result = new ResourceRenamed(convert(context.getPath()), context.getMessage()); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_DELETE)) { _affectedPath = convert(context.getOldPath()); result = new ResourceDeleted(context.getMessage()); } else { _affectedPath = null; result = null; } if (_affectedPath == null) { return null; } return Pair.newPair(_affectedPath, result); }
sessionInfo(context)); } else if (event.kind().equals(StandardWatchEventKind.ENTRY_CREATE)) { _affectedPath = convert(context.getPath()); result = (T) new ResourceAddedEvent(_affectedPath, context.getMessage(), _affectedPath = convert(context.getOldPath()); result = (T) new ResourceRenamedEvent(_affectedPath, convert(context.getPath()), context.getMessage(), sessionInfo(context));