### Question:
AccountController { @PostMapping(value = "add", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") public ResultBean<Integer> add(@Valid @RequestBody Account account) { return new ResultBean<>(accountService.insert(account)); }  @GetMapping("{id}") @ApiOperation(value = "通过id获取账户") ResultBean<Account> getAccount(@ApiParam(name = "id", value = "账户id", required = true)
                                          @Positive(message = "主键必须大于0")
                                          @PathVariable("id") int id); @GetMapping(value = "get") @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") @ApiImplicitParams({ @ApiImplicitParam(paramType = "body", name = "account", value = "account帐号信息", dataType = "Account"), }) ResultBean<Integer> get(@Valid @RequestParam Account account); @PostMapping(value = "add", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") ResultBean<Integer> add(@Valid @RequestBody Account account); @PostMapping(value = "add2", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE) @ApiOperation(value = "新增账户", notes = "返回新生成的主键id") ResultBean<Integer> add2(@Validated(Insert.class) @RequestBody Account account); @GetMapping("/testBusinessException") @ApiOperation(value = "用于测试抛出一个业务异常") ResultBean<?> testBusinessException(); @GetMapping("/testUnknownException") @ApiOperation(value = "用于测试抛出一个未知异常") ResultBean<?> testUnknownException(); void test4();  }### Answer:
@Test public void add() throws Exception { Account account = new Account(); mockMvc.perform(post("/account/add") .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) .content(JACKSON_MAPPER.writeValueAsString(account))) .andDo(print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(model().attribute("msg", "姓名不能为空")); account = new Account("尼古拉斯", 10000.0); mockMvc.perform(post("/account/add") .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) .content(JACKSON_MAPPER.writeValueAsString(account))) .andDo(print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(content().json(JACKSON_MAPPER.writeValueAsString(ResultBean.success(11)))); }