ADD:: Friend remove methods and tests in server.User
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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>();
|
||||
|
||||
Reference in New Issue
Block a user