From 12b05f3b732a8a24e267f7db308cf12da412bb70 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Mon, 1 Apr 2019 16:46:01 +0200 Subject: [PATCH] ADD:: RemoveFriend method and test in client.userService --- .../java/greenify/client/rest/UserService.java | 18 ++++++++++++++++++ src/Client/src/test/java/UserServiceTest.java | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Client/src/main/java/greenify/client/rest/UserService.java b/src/Client/src/main/java/greenify/client/rest/UserService.java index 9252cc8..e0bd827 100644 --- a/src/Client/src/main/java/greenify/client/rest/UserService.java +++ b/src/Client/src/main/java/greenify/client/rest/UserService.java @@ -230,6 +230,24 @@ public class UserService { .encode().toUri(), String.class); } + /** + * Removes a friend from the friendslist of the user. + * @param name the username of the current user. + * @param friend the username of the friend you want to remove. + */ + @SuppressWarnings("Duplicates") + public void removeFriend(String name, String friend) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON_VALUE); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/removeFriend") + .queryParam("name", name) + .queryParam("friend",friend); + HttpEntity entity = new HttpEntity<>(headers); + System.out.println(builder.build().encode().toUri()); + ResponseEntity authenticateResponse = this.restTemplate.getForEntity(builder.build() + .encode().toUri(), String.class); + } + /** * Gets the footprint inputs of the user. * @param name the username of the current user. diff --git a/src/Client/src/test/java/UserServiceTest.java b/src/Client/src/test/java/UserServiceTest.java index 812bc3e..b7d1fa6 100644 --- a/src/Client/src/test/java/UserServiceTest.java +++ b/src/Client/src/test/java/UserServiceTest.java @@ -147,6 +147,14 @@ public class UserServiceTest { userService.addFriend("Eric", "Ceren"); Mockito.verify(userService).addFriend("Eric", "Ceren"); } + + @Test + public void removeFriendTest() throws Exception { + userService.addFriend("Eric", "Ceren"); + Mockito.verify(userService).addFriend("Eric", "Ceren"); + userService.removeFriend("Eric", "Ceren"); + Mockito.verify(userService).removeFriend("Eric", "Ceren"); + } }