### Question:
AccountController { @PostMapping(path = "/account/new") public ResponseEntity<?> createAccount(@Valid @RequestBody final AccountDto account, final BindingResult bindingResult) { final List<String> errors = appUtils.getModelErrors(bindingResult, "id"); if (!errors.isEmpty()) { return ResponseEntity.badRequest().body( AccountResultModel.builder().errors(errors).build()); } try { final AccountDto createdAccount = accountService.createAccount(account); final AccountResultModel result = AccountResultModel.builder().result(createdAccount).build(); return ResponseEntity.ok(result); } catch (final AccountValidationException ex) { final AccountResultModel result = AccountResultModel.builder() .errors(Arrays.asList(ex.getMessage())) .build(); return ResponseEntity.badRequest().body(result); } }  @GetMapping(path = "/account/get/{username}") ResponseEntity<?> getAccount(@PathVariable("username") final String username); @PostMapping(path = "/account/auth") ResponseEntity<?> authenticate(@Valid @RequestBody final AuthDto authDto,
        final BindingResult bindingResult); @PostMapping(path = "/account/new") ResponseEntity<?> createAccount(@Valid @RequestBody final AccountDto account,
        final BindingResult bindingResult); @PostMapping(path = "/account/update") ResponseEntity<?> updateAccount(@Valid @RequestBody final AccountDto account,
        final BindingResult bindingResult); @GetMapping(path = "/account/delete/{id}") ResponseEntity<?> deleteAccount(@PathVariable("id") final String username);  }### Answer:
@Test public void test_createAccount_fail() throws Exception { final AccountDto accountDto = createAccount(); final ObjectMapper objectMapper = new ObjectMapper(); when(accountService.createAccount(accountDto)).thenThrow(new AccountValidationException("Test error.")); mockMvc .perform(post("/account/new").content(objectMapper.writeValueAsString(accountDto)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isBadRequest()); }
@Test public void test_createAccount_success() throws Exception { final AccountDto accountDto = createAccount(); final ObjectMapper objectMapper = new ObjectMapper(); when(accountService.createAccount(accountDto)).thenReturn(accountDto); mockMvc .perform(post("/account/new").content(objectMapper.writeValueAsString(accountDto)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("result.username").value(TEST_USERNAME)) .andExpect(jsonPath("result.emailAddress").value(TEST_EMAIL_ADDRESS)); }
@Test public void test_deleteAccount_success() throws Exception { final AccountDto accountDto = createAccount(); mockMvc.perform(get("/account/delete/" + accountDto.getUsername())) .andExpect(status().isOk()); }