### Question:
CassandraDeviceDataCleaner implements DeviceDataCleaner { @Override public void clean(User user, DeviceId deviceId) throws DaoException { try { cleanFolderSnapshot(user, deviceId); cleanFolderMapping(user, deviceId); } catch (RuntimeException e) { throw new DaoException("An error occured during the user-device cleaning", e); } } @Inject @VisibleForTesting  CassandraDeviceDataCleaner(
			@Named(LoggerModule.CASSANDRA)Logger logger,
			Provider<Session> sessionProvider); @Override void clean(User user, DeviceId deviceId);  }### Answer:
@Test(expected=DaoException.class) public void cleanShouldPropagateExceptionAsDaoException() { cassandraCQLUnit.session.close(); testee.clean(user2, device2.getDevId()); }
@Test public void cleanShouldDoNothingWhenNothingMatch() throws Exception { FolderSyncKey syncKey = new FolderSyncKey("26b7ebcd-9dca-4d89-8725-411223ebb5e8"); CollectionId collectionId = CollectionId.of(2); FolderSnapshot snapshot = FolderSnapshot.nextId(2).folders( ImmutableSet.of(Folder.builder() .displayName("name") .backendId(MailboxPath.of("15")) .collectionId(collectionId) .parentBackendId(MailboxPath.of("12")) .folderType(FolderType.USER_CREATED_CONTACTS_FOLDER).build())); folderSnapshotDao.create(user1, device1, syncKey, snapshot); testee.clean(user2, device2.getDevId()); assertThatUserHasFolderSnapshot(user1, device1, syncKey); assertThatUserHasFolderMapping(user1, device1, collectionId); }
@Test public void cleanShouldDropUserDeviceFolderSnapshotAndMapping() throws Exception { FolderSyncKey syncKey = new FolderSyncKey("26b7ebcd-9dca-4d89-8725-411223ebb5e8"); CollectionId collectionId = CollectionId.of(2); FolderSnapshot snapshot = FolderSnapshot.nextId(2).folders( ImmutableSet.of(Folder.builder() .displayName("name") .backendId(MailboxPath.of("15")) .collectionId(collectionId) .parentBackendId(MailboxPath.of("12")) .folderType(FolderType.USER_CREATED_CONTACTS_FOLDER).build())); folderSnapshotDao.create(user1, device1, syncKey, snapshot); folderSnapshotDao.create(user1, device2, syncKey, snapshot); folderSnapshotDao.create(user2, device1, syncKey, snapshot); folderSnapshotDao.create(user2, device2, syncKey, snapshot); testee.clean(user2, device1.getDevId()); assertThatUserHasFolderSnapshot(user1, device1, syncKey); assertThatUserHasFolderSnapshot(user1, device2, syncKey); assertThatUserHasNoFolderSnapshot(user2, device1, syncKey); assertThatUserHasFolderSnapshot(user2, device2, syncKey); assertThatUserHasFolderMapping(user1, device1, collectionId); assertThatUserHasFolderMapping(user1, device2, collectionId); assertThatUserHasNoFolderMapping(user2, device1, collectionId); assertThatUserHasFolderMapping(user2, device2, collectionId); }