### Question:
FolderSnapshotService { @VisibleForTesting Function<BackendId, CollectionDeletion> folderToCollectionDeletion(final Map<BackendId, Folder> knownFolders) { return new Function<BackendId, CollectionDeletion>() { @Override public CollectionDeletion apply(BackendId id) { return CollectionDeletion.builder() .collectionId(knownFolders.get(id).getCollectionId()) .build(); } }; } @Inject protected  FolderSnapshotService(FolderSnapshotDao folderSnapshotDao); FolderSnapshot findFolderSnapshot(UserDataRequest udr, FolderSyncKey folderSyncKey); FolderSnapshot snapshot(UserDataRequest udr, FolderSyncKey outgoingSyncKey,
			FolderSnapshot knownSnapshot, BackendFolders currentFolders); CollectionId createSnapshotAddingFolder(UserDataRequest udr, FolderSyncKey outgoingSyncKey,
			FolderSnapshot knownSnapshot, BackendFolder backendFolder); HierarchyCollectionChanges buildDiff(final FolderSnapshot knownSnapshot, final FolderSnapshot currentSnapshot);  }### Answer:
@Test(expected=NullPointerException.class) public void folderToCollectionDeletionShouldNPEWhenNullFolders() { Map<BackendId, Folder> folders = null; BackendId id = new TestBackendId("4"); mocks.replay(); try { testee.folderToCollectionDeletion(folders).apply(id); } finally { mocks.verify(); } }
@Test(expected=NullPointerException.class) public void folderToCollectionDeletionShouldNPEWhenNullCollectionId() { Map<BackendId, Folder> folders = ImmutableMap.<BackendId, Folder>of(); BackendId id = null; mocks.replay(); try { testee.folderToCollectionDeletion(folders).apply(id); } finally { mocks.verify(); } }
@Test(expected=NullPointerException.class) public void folderToCollectionDeletionShouldNPEWhenFolderNotFound() { Map<BackendId, Folder> folders = ImmutableMap.<BackendId, Folder>of(); BackendId id = new TestBackendId("5"); mocks.replay(); try { testee.folderToCollectionDeletion(folders).apply(id); } finally { mocks.verify(); } }
@Test public void folderToCollectionDeletionShouldSucceedWhenFolderFound() { Map<BackendId, Folder> folders = ImmutableMap.<BackendId, Folder>of( new TestBackendId("5"), Folder.builder() .backendId(new TestBackendId("5")) .collectionId(CollectionId.of(2)) .parentBackendId(new TestBackendId("12")) .displayName("name") .folderType(FolderType.DEFAULT_CALENDAR_FOLDER) .build()); BackendId id = new TestBackendId("5"); mocks.replay(); assertThat(testee.folderToCollectionDeletion(folders).apply(id)) .isEqualTo(CollectionDeletion.builder().collectionId(CollectionId.of(2)).build()); mocks.verify(); }