### Question:
AcmCaseFileClosedListener implements ApplicationListener<CaseEvent> { @Override public void onApplicationEvent(CaseEvent event) { boolean checkIntegrationEnabled = alfrescoRecordsService.getRmaConfig().getDeclareRecordsOnCaseClose(); if (!checkIntegrationEnabled) { return; } boolean shouldDeclareRecords = shouldDeclareRecords(event); if (shouldDeclareRecords) { CaseFile caseFile = event.getCaseFile(); if (null != caseFile) { String principal = event.getUserId(); AcmAuthentication authentication; try { authentication = authenticationManager.getAcmAuthentication( new UsernamePasswordAuthenticationToken(principal, principal)); } catch (AuthenticationServiceException e) { authentication = new AcmAuthentication(Collections.emptySet(), principal, "", true, principal); } getAlfrescoRecordsService().declareAllContainerFilesAsRecords(authentication, caseFile.getContainer(), event.getEventDate(), caseFile.getCaseNumber()); } } }  @Override void onApplicationEvent(CaseEvent event); AlfrescoRecordsService getAlfrescoRecordsService(); void setAlfrescoRecordsService(AlfrescoRecordsService alfrescoRecordsService); AcmAuthenticationManager getAuthenticationManager(); void setAuthenticationManager(AcmAuthenticationManager authenticationManager);  }### Answer:
@Test public void doNotProceed_shouldNotDeclareRecords() { rmaConfig.setDeclareRecordsOnCaseClose(false); expect(mockService.getRmaConfig()).andReturn(rmaConfig); CaseEvent caseEvent = new CaseEvent(new CaseFile(), "ipAddress", "user", "eventType", new Date(), true, mockAuthentication); replayAll(); unit.onApplicationEvent(caseEvent); verifyAll(); }
@Test public void notACaseClosedEvent_shouldNotDeclareRecords() { rmaConfig.setDeclareRecordsOnCaseClose(true); expect(mockService.getRmaConfig()).andReturn(rmaConfig); CaseEvent caseEvent = new CaseEvent(new CaseFile(), "ipAddress", "user", "caseOpenEvent", new Date(), true, mockAuthentication); replayAll(); unit.onApplicationEvent(caseEvent); verifyAll(); }
@Test public void caseClosedEvent_shouldDeclareRecords() { CaseFile caseFile = new CaseFile(); caseFile.setContainer(new AcmContainer()); caseFile.setCaseNumber("caseNumber"); String user = "user"; Capture<Authentication> captureAuth = Capture.newInstance(); rmaConfig.setDeclareRecordsOnCaseClose(true); expect(mockService.getRmaConfig()).andReturn(rmaConfig); expect(mockAuthenticationManager.getAcmAuthentication(new UsernamePasswordAuthenticationToken(user, user))) .andReturn(new AcmAuthentication(Collections.emptySet(), user, "", true, user)); CaseEvent caseEvent = new CaseEvent(caseFile, "ipAddress", user, AlfrescoRmaPluginConstants.CASE_CLOSED_EVENT, new Date(), true, new AcmAuthentication(Collections.emptySet(), user, "", true, user)); mockService.declareAllContainerFilesAsRecords( capture(captureAuth), eq(caseFile.getContainer()), anyObject(Date.class), eq(caseFile.getCaseNumber())); replayAll(); unit.onApplicationEvent(caseEvent); verifyAll(); Authentication actual = captureAuth.getValue(); assertEquals(user, actual.getName()); }