### Question:
EmailMessageOperations { public EmailMessageResponse updateMessage(EmailMessageUpdateRequest req){ req.validate(); Status requestStatus = Status.fromValue(req.getStatus()); EmailMessage emailMessage = emailMessageRepo.findEmailMessageByStatus(requestStatus); if(emailMessage == null){ ErrorType.MESSAGE_NOT_FOUND.throwException(); } emailMessage.setEmailMessage(req.getEmailMessage()); emailMessageRepo.save(emailMessage); EmailMessageResponse response = new EmailMessageResponse(emailMessage); return response; } EmailMessageOperations(EmailMessageRepo emailMessageRepo); EmailMessageResponse getMessageByStatus(String status); EmailMessageResponse updateMessage(EmailMessageUpdateRequest req);  }### Answer:
@Test public void updateMessage() throws Exception { EmailMessageUpdateRequest request = new EmailMessageUpdateRequest(); request.setStatus("COMPLETED"); request.setEmailMessage("EMAIL MESSAGE RESPONSE"); Status requestStatus = Status.fromValue(request.getStatus()); EmailMessage emailMessage = new EmailMessage(requestStatus, request.getEmailMessage()); emailMessage.setId(2); when(repo.findEmailMessageByStatus(requestStatus)).thenReturn(emailMessage); when(repo.save(emailMessage)).thenReturn(emailMessage); EmailMessageResponse response = operations.updateMessage(request); verify(repo, times(1)).findEmailMessageByStatus(requestStatus); verify(repo, times(1)).save(emailMessage); assertEquals(response.getData().getEmailMessage(), emailMessage.getEmailMessage()); assertEquals(response.getData().getStatus(), emailMessage.getStatus()); assertEquals(response.getData().getId(), emailMessage.getId()); }
@Test(expected = IdeaLabApiException.class) public void updateMessage_MessageNotFound() { EmailMessageUpdateRequest request = new EmailMessageUpdateRequest(); request.setStatus("COMPLETED"); request.setEmailMessage("EMAIL MESSAGE RESPONSE"); Status requestStatus = Status.fromValue(request.getStatus()); EmailMessage emailMessage = null; when(repo.findEmailMessageByStatus(requestStatus)).thenReturn(emailMessage); when(repo.save(emailMessage)).thenReturn(emailMessage); EmailMessageResponse response = operations.updateMessage(request); }