### Question:
EmailMessageOperations { public EmailMessageResponse getMessageByStatus(String status){ Status requestStatus = Status.fromValue(status); if(requestStatus == null || !requestStatus.isValid()){ ErrorType.REQUEST_STATUS_IS_NOT_VALID.throwException(); } EmailMessage emailMessage = emailMessageRepo.findEmailMessageByStatus(requestStatus); if(emailMessage == null || emailMessage.getEmailMessage() == null){ ErrorType.MESSAGE_NOT_FOUND.throwException(); } EmailMessageResponse response = new EmailMessageResponse(emailMessage); return response; } EmailMessageOperations(EmailMessageRepo emailMessageRepo); EmailMessageResponse getMessageByStatus(String status); EmailMessageResponse updateMessage(EmailMessageUpdateRequest req);  }### Answer:
@Test public void getMessageByStatus() throws Exception { String status = "COMPLETED"; Status requestStatus = Status.fromValue(status); EmailMessage emailMessage = new EmailMessage(Status.fromValue("COMPLETED"), "EMAIL MESSAGE RESPONSE"); when(repo.findEmailMessageByStatus(requestStatus)).thenReturn(emailMessage); EmailMessageResponse response = operations.getMessageByStatus("COMPLETED"); verify(repo, times(1)).findEmailMessageByStatus(requestStatus); assertEquals(response.getData().getEmailMessage(), emailMessage.getEmailMessage()); assertEquals(response.getData().getStatus(), emailMessage.getStatus()); }
@Test(expected = IdeaLabApiException.class) public void getMessageByStatus_StatusNotValid() { String status = "COMPLETED"; Status requestStatus = Status.fromValue(status); EmailMessage emailMessage = new EmailMessage(Status.fromValue("COMPLETED"), "EMAIL MESSAGE RESPONSE"); when(repo.findEmailMessageByStatus(requestStatus)).thenReturn(emailMessage); EmailMessageResponse response = operations.getMessageByStatus("NOT_VALID_STATUS"); }
@Test(expected = IdeaLabApiException.class) public void getMessageByStatus_MessageNotFound() { String status = "COMPLETED"; Status requestStatus = Status.fromValue(status); EmailMessage emailMessage = null; when(repo.findEmailMessageByStatus(requestStatus)).thenReturn(emailMessage); EmailMessageResponse response = operations.getMessageByStatus("COMPLETED"); }