### Question:
GreetingController { @PostMapping(value = "/sms_greeting") BaseResponse sendSmsGreeting(@RequestBody @Validated GreetingRequest request) { greetingService.greeting(request.getUserId()); return BaseResponse.builder().message("greeting sent").build(); }    }### Answer:
@Test public void testGreeting() { String userId = UUID.randomUUID().toString(); AccountDto accountDto = AccountDto.builder() .name("test_user001") .phoneNumber("11111111111") .email("test_user001@staffjoy.xyz") .id(userId) .memberSince(Instant.now().minus(30, ChronoUnit.DAYS)) .confirmedAndActive(true) .photoUrl("https: .build(); when(accountClient.getAccount(AuthConstant.AUTHORIZATION_BOT_SERVICE, userId)) .thenReturn(new GenericAccountResponse(accountDto)); when(mailClient.send(any(EmailRequest.class))).thenReturn(BaseResponse.builder().message("mail sent").build()); BaseResponse baseResponse = botClient.sendSmsGreeting(GreetingRequest.builder().userId(userId).build()); log.info(baseResponse.toString()); assertThat(baseResponse.isSuccess()).isTrue(); ArgumentCaptor<EmailRequest> argument = ArgumentCaptor.forClass(EmailRequest.class); verify(mailClient, times(1)).send(argument.capture()); EmailRequest emailRequest = argument.getValue(); assertThat(emailRequest.getTo()).isEqualTo(accountDto.getEmail()); assertThat(emailRequest.getName()).isEqualTo(accountDto.getName()); assertThat(emailRequest.getSubject()).isEqualTo("Staffjoy Greeting"); assertThat(emailRequest.getHtmlBody()).isEqualTo(BotConstant.GREETING_EMAIL_TEMPLATE); }
@Test public void testGreetingException() { String userId = UUID.randomUUID().toString(); when(accountClient.getAccount(AuthConstant.AUTHORIZATION_BOT_SERVICE, userId)) .thenThrow(new RuntimeException("get account failure exception")); BaseResponse baseResponse = botClient.sendSmsGreeting(GreetingRequest.builder().userId(userId).build()); log.info(baseResponse.toString()); assertThat(baseResponse.isSuccess()).isFalse(); assertThat(baseResponse.getCode()).isEqualTo(ResultCode.FAILURE); }