### Question:
EcmNodeDeletedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmNodeDeleted(EcmEvent ecmEvent) { getAuditPropertyEntityAdapter().setUserId(ecmEvent.getUserId()); EcmFile deleteFile = getFolderAndFilesUtils().lookupArkCaseFile(ecmEvent.getNodeId()); if (deleteFile != null) { try { String message = String.format(DELETE_MESSAGE, deleteFile.getObjectType().toLowerCase()); getFileService().removeLockAndSendMessage(deleteFile.getId(), message); getFileService().deleteFileFromArkcase(deleteFile.getId()); log.info("Deleted file with CMIS ID [{}]", ecmEvent.getNodeId()); } catch (PersistenceException e) { log.error("Could not delete file with id [{}], {} ", deleteFile.getId(), e.getMessage(), e); } } else { AcmFolder deleteFolder = getFolderAndFilesUtils().lookupArkCaseFolder(ecmEvent.getNodeId()); if (deleteFolder != null) { String message = String.format(DELETE_MESSAGE, deleteFolder.getObjectType().toLowerCase()); getFolderService().removeLockAndSendMessage(deleteFolder.getId(), message); getFolderService().deleteFolderContent(deleteFolder, AuthenticationUtils.getUsername()); log.info("Deleted folder with CMIS ID [{}]", ecmEvent.getNodeId()); } } }  void onEcmNodeDeleted(EcmEvent ecmEvent); @Override void onApplicationEvent(EcmEvent ecmEvent); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileService getFileService(); void setFileService(EcmFileService fileService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils);  }### Answer:
@Test public void onEcmNodeDeleted_ifFileIsDeletedInContentRepository_thenDeleteItFromArkcase() { auditPropertyEntityAdapter.setUserId(nodeDeletedEvent.getUserId()); EcmFile file = new EcmFile(); file.setFileId(111L); when(ecmFileDao.findByCmisFileId(nodeDeletedEvent.getNodeId())).thenReturn(Arrays.asList(file)); unit.onEcmNodeDeleted(nodeDeletedEvent); verify(ecmFileDao, times(1)).findByCmisFileId(nodeDeletedEvent.getNodeId()); verify(acmFolderDao, times(0)).findByCmisFolderId(nodeDeletedEvent.getNodeId()); }
@Test public void onEcmNodeDeleted_ifFolderIsDeletedInContentRepository_thenDeleteItFromArkcase() { auditPropertyEntityAdapter.setUserId(nodeDeletedEvent.getUserId()); AcmFolder folder = new AcmFolder(); folder.setId(222L); when(ecmFileDao.findByCmisFileId(nodeDeletedEvent.getNodeId())).thenThrow(new NoResultException()); when(acmFolderDao.findByCmisFolderId(nodeDeletedEvent.getNodeId())).thenReturn(folder); Authentication auth = new UsernamePasswordAuthenticationToken("test", "test"); SecurityContextHolder.getContext().setAuthentication(auth); unit.onEcmNodeDeleted(nodeDeletedEvent); verify(ecmFileDao, times(1)).findByCmisFileId(nodeDeletedEvent.getNodeId()); verify(acmFolderDao, times(1)).findByCmisFolderId(nodeDeletedEvent.getNodeId()); }