### Question:
EcmFolderCreatedEventHandler implements ApplicationListener<EcmEvent> { public void onEcmFolderCreated(EcmEvent folderCreated) { log.debug("Handling new folder {}", folderCreated.getNodeId()); if (getFolderAndFilesUtils().lookupArkCaseFolder(folderCreated.getNodeId()) != null) { return; } AcmFolder parentFolder = getFolderAndFilesUtils().lookupArkCaseFolder(folderCreated.getParentNodeId()); if (parentFolder == null) { log.debug("Parent folder is not in ArkCase, so not creating the new folder {}", folderCreated.getNodeId()); return; } AcmFolder newFolder = prepareFolder(parentFolder, folderCreated); try { getAuditPropertyEntityAdapter().setUserId(folderCreated.getUserId()); AcmFolder created = getFolderDao().save(newFolder); getFileParticipantService().setFolderParticipantsFromParentFolder(created); created = getFolderDao().save(created); log.debug("Finished creating new folder with node id {}, ArkCase id {}", folderCreated.getNodeId(), created.getId()); } catch (PersistenceException pe) { log.error("Cannot create new folder with CMIS ID {}: [{}]", folderCreated.getNodeId(), pe.getMessage(), pe); } }  void onEcmFolderCreated(EcmEvent folderCreated); @Override void onApplicationEvent(EcmEvent ecmEvent); AcmFolderDao getFolderDao(); void setFolderDao(AcmFolderDao folderDao); AcmFolderService getFolderService(); void setFolderService(AcmFolderService folderService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); EcmFileParticipantService getFileParticipantService(); void setFileParticipantService(EcmFileParticipantService fileParticipantService); FolderAndFilesUtils getFolderAndFilesUtils(); void setFolderAndFilesUtils(FolderAndFilesUtils folderAndFilesUtils);  }### Answer:
@Test public void onEcmFolderCreated_createNewArkCaseFolder() throws Exception { AcmFolder parentFolder = new AcmFolder(); parentFolder.setCmisRepositoryId("cmisRepositoryId"); Capture<AcmFolder> newFolder = Capture.newInstance(); expect(folderAndFilesUtils.lookupArkCaseFolder(folderCreated.getNodeId())).andReturn(null); expect(folderAndFilesUtils.lookupArkCaseFolder(folderCreated.getParentNodeId())).andReturn(parentFolder); expect(acmFolderService.getCmisRepositoryId(parentFolder)).andReturn(parentFolder.getCmisRepositoryId()); auditPropertyEntityAdapter.setUserId(folderCreated.getUserId()); AcmFolder savedFolder = new AcmFolder(); expect(acmFolderDao.save(capture(newFolder))).andReturn(savedFolder); fileParticipantService.setFolderParticipantsFromParentFolder(savedFolder); expectLastCall(); expect(acmFolderDao.save(savedFolder)).andReturn(savedFolder); replay(mocks); unit.onEcmFolderCreated(folderCreated); verify(mocks); AcmFolder created = newFolder.getValue(); assertNotNull(created); assertEquals(parentFolder, created.getParentFolder()); assertEquals(folderCreated.getNodeName(), created.getName()); assertEquals(folderCreated.getNodeId(), created.getCmisFolderId()); assertEquals(parentFolder.getCmisRepositoryId(), created.getCmisRepositoryId()); }
@Test public void onEcmFolderCreated_ifAlreadyInArkcase_thenNoFurtherAction() throws Exception { expect(folderAndFilesUtils.lookupArkCaseFolder(folderCreated.getNodeId())).andReturn(new AcmFolder()); replay(mocks); unit.onEcmFolderCreated(folderCreated); verify(mocks); }
@Test public void onEcmFolderCreated_ifParentFolderNotInArkcase_thenNoFurtherAction() throws Exception { expect(folderAndFilesUtils.lookupArkCaseFolder(folderCreated.getNodeId())).andReturn(null); expect(folderAndFilesUtils.lookupArkCaseFolder(folderCreated.getParentNodeId())).andReturn(null); replay(mocks); unit.onEcmFolderCreated(folderCreated); verify(mocks); }