### Question:
AcmComplaintClosedListener implements ApplicationListener<ComplaintClosedEvent> { @Override public void onApplicationEvent(ComplaintClosedEvent event) { AlfrescoRmaConfig rmaConfig = alfrescoRecordsService.getRmaConfig(); boolean proceed = rmaConfig.getIntegrationEnabled() && rmaConfig.getDeclareRecordsOnComplaintClose(); if (!proceed) { return; } if (!event.isSucceeded()) { LOG.trace("Returning - closing complaint was not successful"); return; } Complaint complaint = (Complaint) event.getSource(); if (null != complaint) { 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, complaint.getContainer(), event.getEventDate(), complaint.getComplaintNumber()); } }  @Override void onApplicationEvent(ComplaintClosedEvent event); AlfrescoRecordsService getAlfrescoRecordsService(); void setAlfrescoRecordsService(AlfrescoRecordsService alfrescoRecordsService); AcmAuthenticationManager getAuthenticationManager(); void setAuthenticationManager(AcmAuthenticationManager authenticationManager);  }### Answer:
@Test public void doNotProceed_shouldNotDeclareRecords() { rmaConfig.setDeclareRecordsOnComplaintClose(false); expect(mockService.getRmaConfig()).andReturn(rmaConfig); ComplaintClosedEvent event = new ComplaintClosedEvent(new Complaint(), true, "user", new Date()); replayAll(); unit.onApplicationEvent(event); verifyAll(); }
@Test public void complaintClosedEvent_shouldDeclareRecords() { Complaint complaint = new Complaint(); complaint.setContainer(new AcmContainer()); complaint.setComplaintNumber("complaintNumber"); rmaConfig.setDeclareRecordsOnComplaintClose(true); expect(mockService.getRmaConfig()).andReturn(rmaConfig); expect(mockAuthenticationManager.getAcmAuthentication(anyObject())) .andReturn(new AcmAuthentication(null, "", "", true, "")); mockService.declareAllContainerFilesAsRecords( anyObject(Authentication.class), eq(complaint.getContainer()), anyObject(Date.class), eq(complaint.getComplaintNumber())); ComplaintClosedEvent event = new ComplaintClosedEvent(complaint, true, "user", new Date()); replayAll(); unit.onApplicationEvent(event); verifyAll(); }