### Question:
UserController { @PreAuthorize("#oauth2.hasScope('server')") @GetMapping(value="/username/{username}", produces="application/json") public User selectByUsername(@PathVariable("username") String username) { User user = userService.selectByUsername(username); if (user != null) return userService.truncate(user); else return null; }  @GetMapping(value ="/id/{id}", produces ="application/json") User getUser(@PathVariable("id") Long id); @PreAuthorize("#oauth2.hasScope('server')") @GetMapping(value ="/user", produces ="application/json") Principal getUser(Authentication authentication); @GetMapping(value ="/all", produces ="application/json") Iterable<User> getAllUsers(); @PreAuthorize("#oauth2.hasScope('server')") @GetMapping(value="/username/{username}", produces="application/json") User selectByUsername(@PathVariable("username") String username); @PreAuthorize("hasRole('ADMIN') or principal.username == #username") @PutMapping(value="/update/{username}", produces="application/json") User updateUser(@PathVariable("username") String username,
                           @RequestParam(value = "id", defaultValue = "0") Long id,
                           @RequestParam(value = "password", defaultValue = "") String password,
                           @RequestParam(value = "mail", defaultValue = "") String mail,
                           @RequestParam(value = "imgUrl", defaultValue = "") String imgUrl); @PreAuthorize("hasRole('ADMIN') or principal.username == #username") @DeleteMapping(value="/delete/username/{username}") void deleteUserByUsername(
            @PathVariable("username") String username); @PreAuthorize("hasRole('ADMIN')") @DeleteMapping(value="/delete/id/{id}") void deleteUserById(
            @PathVariable("id") Long id);  }### Answer:
@Test public void deleteTest() throws Exception { mvc.perform(delete("/delete/username/root")) .andExpect(status().isOk()); Assert.assertNull(userService.selectByUsername("root")); MvcResult mvcResult = mvc.perform(post("/verify") .contentType(MediaType.APPLICATION_JSON) .content("{\"username\":\"root\", \"password\":\"bamdb\", \"mail\":\"bamdb@outlook.com\", \"img_url\":null, \"role\":0}")) .andExpect(status().isOk()) .andReturn(); int result = Integer.valueOf(mvcResult.getResponse().getContentAsString()); mvc.perform(get("/signup?hashCode="+result)) .andExpect(status().is3xxRedirection()); Long id = userService.selectAll().iterator().next().getId(); mvc.perform(get("/id/" + id).contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); mvc.perform(delete("/delete/id/" + id)) .andExpect(status().isOk()); Assert.assertNull(userService.selectUserById(id)); }