ADD:: Friend remove methods and tests in server.User

This commit is contained in:
Merel Steenbergen
2019-04-01 16:36:12 +02:00
parent 26693e8782
commit 52291ac10f
3 changed files with 37 additions and 3 deletions

View File

@@ -18,9 +18,9 @@ apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'
application {
mainClassName = 'greenify.server.Application'
}
//application {
// mainClassName = 'greenify.server.Application'
//}
repositories {
mavenCentral()

View File

@@ -208,6 +208,19 @@ public class User {
}
}
/**
* Removes a friend from the friendslist of the user.
* @param user the friend you want to remove.
*/
public void removeFriend(User user) {
if (!friends.contains(user)) {
throw new ApplicationException("This user is not your friend!");
} else {
friends.remove(user);
System.out.print("Friend removed");
}
}
/**
* This method gets a human readable (JSON) object.
* @return the JSON form of the object.

View File

@@ -125,6 +125,27 @@ public class UserTest {
});
}
@Test
public void removeFriendValidTest() {
User test = new User(1L, "greenify", "password");
List<User> friendList = new ArrayList<>();
friendList.add(test);
User user = new User(1L, "green", "pass");
user.setFriends(friendList);
assertEquals(user.getFriends(), friendList);
user.removeFriend(test);
assertEquals(user.getFriends(), new ArrayList<User>());
}
@Test
public void removeFriendInvalidTest() {
User user = new User(1L, "greenify", "password");
User test = new User(2L, "user", "pass");
assertThrows(ApplicationException.class, () -> {
user.removeFriend(test);
});
}
@Test
public void setFriendTest() {
List<User> friends = new ArrayList<User>();