Friend list to JSON method added
This commit is contained in:
@@ -143,6 +143,17 @@ public class User {
|
||||
+ this.password + ")";
|
||||
}
|
||||
|
||||
public String friendsToString(){
|
||||
String result = "friends=[";
|
||||
for(User u : friends){
|
||||
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
|
||||
}
|
||||
if(result.endsWith(", ")){
|
||||
return result.substring(0, result.lastIndexOf(",")) + "]";
|
||||
}
|
||||
return result + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other instanceof User) {
|
||||
|
||||
@@ -96,7 +96,6 @@ public class UserTest {
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "merel", "password");
|
||||
assertEquals(first.getFriends(), second.getFriends());
|
||||
System.out.print(second);
|
||||
first.addFriend(second);
|
||||
ArrayList<User> test = new ArrayList<User>();
|
||||
test.add(second);
|
||||
@@ -109,6 +108,16 @@ public class UserTest {
|
||||
assertEquals(test.getFriends(), new ArrayList<User>());
|
||||
assertThrows(ApplicationException.class, () -> {
|
||||
test.addFriend(test);
|
||||
}); }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void friendsToStringTest(){
|
||||
User first = new User(1L, "greenify", "password");
|
||||
User second = new User(1L, "merel", "password");
|
||||
first.addFriend(second);
|
||||
assertEquals(first.friendsToString(), "friends=[{name=merel, footprint=0.0}]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user