ADD::RemoveFriend method and test in server.userController
This commit is contained in:
@@ -155,13 +155,25 @@ public class UserController {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method adds friend for a user.
|
||||
* This method adds a friend to a user.
|
||||
* @param name name of the user
|
||||
*
|
||||
* @param friend the name of the user you want to add as a friend.
|
||||
*/
|
||||
@RequestMapping("/addFriend")
|
||||
public void addFriend(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "friend") String friend) {
|
||||
userService.addFriend(name, friend);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes a friend from a user.
|
||||
* @param name name of the user
|
||||
* @param friend name of the friend you want to remove
|
||||
*/
|
||||
@RequestMapping("/removeFriend")
|
||||
public void removeFriend(@RequestParam(value = "name") String name,
|
||||
@RequestParam(value = "friend") String friend) {
|
||||
userService.removeFriend(name, friend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,34 @@ public class UserControllerTest {
|
||||
assertEquals("merel", arg2Captor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeFriendTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||
mvc.perform(get("/addFriend")
|
||||
.param("name", "ceren")
|
||||
.param("friend", "merel")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1))
|
||||
.addFriend(arg1Captor.capture(), arg2Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
assertEquals("merel", arg2Captor.getValue());
|
||||
|
||||
mvc.perform(get("/removeFriend")
|
||||
.param("name", "ceren")
|
||||
.param("friend", "merel")
|
||||
.accept(MediaType.APPLICATION_JSON))
|
||||
.andDo(print())
|
||||
.andExpect(status().isOk());
|
||||
verify(userService, times(1)).
|
||||
removeFriend(arg1Captor.capture(), arg2Captor.capture());
|
||||
assertEquals("ceren", arg1Captor.getValue());
|
||||
assertEquals("merel", arg2Captor.getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInputMapTest() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
Reference in New Issue
Block a user