### Question:
LibraryFileUpdateNotifier { public void onBatchIndexEvent(@Observes final BatchIndexEvent event) { event.getIndexEvents() .stream() .flatMap(evt -> { switch (evt.getKind()) { case Deleted: return Stream.of(((IndexEvent.DeletedEvent) evt).getDeleted().getKey()); case NewlyIndexed: return Stream.of(((IndexEvent.NewlyIndexedEvent) evt).getKObject().getKey()); case Renamed: return Stream.of(((IndexEvent.RenamedEvent) evt).getTarget().getKey()); default: return Stream.empty(); } }) .map(pathStr -> { final Path path = getPath(pathStr); final WorkspaceProject project = workspaceProjectService.resolveProject(convertPath(path)); final String repositoryId = project.getRepository().getIdentifier(); final String branchName = (path instanceof JGitPathImpl) ? ((JGitPathImpl) path).getRefTree() : null; return new RepositoryFileListUpdatedEvent(repositoryId, branchName); }) .distinct() .forEach(repositoryFileListUpdatedEvent::fire); } @Inject  LibraryFileUpdateNotifier(final WorkspaceProjectService workspaceProjectService,
                                     final Event<RepositoryFileListUpdatedEvent> repositoryFileListUpdatedEvent); void onBatchIndexEvent(@Observes final BatchIndexEvent event);  }### Answer:
@Test public void onBatchIndexEventDoNothingWhenEmptyEventList() { BatchIndexEvent event = mock(BatchIndexEvent.class); doReturn(Collections.emptyList()).when(event).getIndexEvents(); libraryFileUpdateNotifier.onBatchIndexEvent(event); verify(repositoryFileListUpdatedEvent, never()).fire(any(RepositoryFileListUpdatedEvent.class)); }
@Test public void onBatchIndexEventNotifyOnceForSameProjectAndBranch() { this.prepareNewWorkspaceProjectMock(Collections.singletonMap("branch", "a/file/path"), "myRepositoryId"); List<IndexEvent> indexEvents = Collections.nCopies(10, buildIndexedEvent("a/file/path")); libraryFileUpdateNotifier.onBatchIndexEvent(buildBatchIndexEvent(indexEvents)); verify(repositoryFileListUpdatedEvent, times(1)) .fire(any(RepositoryFileListUpdatedEvent.class)); }
@Test public void onBatchIndexEventNotifyForSameProjectDistinctBranches() { Map<String, String> branchPathMap = new HashMap<String, String>() {{ put("branchA", "a/file/pathA"); put("branchB", "a/file/pathB"); put("branchC", "a/file/pathC"); }}; this.prepareNewWorkspaceProjectMock(branchPathMap, "myRepositoryId"); List<IndexEvent> indexEvents = new ArrayList<IndexEvent>() {{ add(buildIndexedEvent("a/file/pathA")); add(buildIndexedEvent("a/file/pathB")); add(buildIndexedEvent("a/file/pathC")); }}; libraryFileUpdateNotifier.onBatchIndexEvent(buildBatchIndexEvent(indexEvents)); verify(repositoryFileListUpdatedEvent, times(3)) .fire(any(RepositoryFileListUpdatedEvent.class)); }
@Test public void onBatchIndexEventNotifyDistinctProjects() { this.prepareNewWorkspaceProjectMock(Collections.singletonMap("branchA", "a/file/pathA"), "myRepositoryIdA"); this.prepareNewWorkspaceProjectMock(Collections.singletonMap("branchB", "a/file/pathB"), "myRepositoryIdB"); List<IndexEvent> indexEvents = new ArrayList<IndexEvent>() {{ add(buildIndexedEvent("a/file/pathA")); add(buildIndexedEvent("a/file/pathB")); }}; libraryFileUpdateNotifier.onBatchIndexEvent(buildBatchIndexEvent(indexEvents)); verify(repositoryFileListUpdatedEvent, times(2)) .fire(any(RepositoryFileListUpdatedEvent.class)); }