@Test public void test_should_return_error_message_when_unhandled_exception_occurs() throws Exception { final OtpRequest expectedOtpRequest = new OtpRequest("mobileNumber", "tenantId", null, "CITIZEN"); final String exceptionMessage = "Some exception message"; doThrow(new RuntimeException(exceptionMessage)).when(otpService).sendOtp(expectedOtpRequest); mockMvc.perform(post("/v1/_send").contentType(MediaType.APPLICATION_JSON_UTF8) .content(resources.getFileContents("invalidOtpSendRequest.json"))) .andExpect(status().isInternalServerError()).andExpect(content().string(exceptionMessage)); }
@PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) public OtpResponse sendOtp(@RequestBody OtpRequest otpRequest) { otpService.sendOtp(otpRequest.toDomain()); return new OtpResponse(null, true); }
OtpController { @PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) public OtpResponse sendOtp(@RequestBody OtpRequest otpRequest) { otpService.sendOtp(otpRequest.toDomain()); return new OtpResponse(null, true); } }
OtpController { @PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) public OtpResponse sendOtp(@RequestBody OtpRequest otpRequest) { otpService.sendOtp(otpRequest.toDomain()); return new OtpResponse(null, true); } @Autowired  OtpController(OtpService otpService); }
OtpController { @PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) public OtpResponse sendOtp(@RequestBody OtpRequest otpRequest) { otpService.sendOtp(otpRequest.toDomain()); return new OtpResponse(null, true); } @Autowired  OtpController(OtpService otpService); @PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) OtpResponse sendOtp(@RequestBody OtpRequest otpRequest); }
OtpController { @PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) public OtpResponse sendOtp(@RequestBody OtpRequest otpRequest) { otpService.sendOtp(otpRequest.toDomain()); return new OtpResponse(null, true); } @Autowired  OtpController(OtpService otpService); @PostMapping("/v1/_send") @ResponseStatus(HttpStatus.CREATED) OtpResponse sendOtp(@RequestBody OtpRequest otpRequest);  }