Fix checkstyle errors
This commit is contained in:
@@ -7,16 +7,11 @@ import lombok.Data;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import javax.persistence.ElementCollection;
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.GenerationType;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import javax.persistence.Table;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@@ -27,7 +22,6 @@ public class User {
|
|||||||
@Id
|
@Id
|
||||||
@NotNull
|
@NotNull
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
// @Column(name = "id")
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -114,15 +108,19 @@ public class User {
|
|||||||
this.footPrintInputs = footPrintInputs;
|
this.footPrintInputs = footPrintInputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<User> getFriends(){
|
public ArrayList<User> getFriends() {
|
||||||
return (ArrayList<User>)this.friends;
|
return (ArrayList<User>)this.friends;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFriend(User user){
|
/**
|
||||||
if(user.equals(this)){
|
* Adds a friend to the friendslist of the user.
|
||||||
|
* @param user the friend you want to add.
|
||||||
|
*/
|
||||||
|
public void addFriend(User user) {
|
||||||
|
if (user.equals(this)) {
|
||||||
throw new ApplicationException("Cannot add yourself as a friend");
|
throw new ApplicationException("Cannot add yourself as a friend");
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
friends.add(user);
|
friends.add(user);
|
||||||
System.out.print("Friend added!");
|
System.out.print("Friend added!");
|
||||||
}
|
}
|
||||||
@@ -143,12 +141,16 @@ public class User {
|
|||||||
+ this.password + ")";
|
+ this.password + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the name and score of the friends in JSON. Needed for the leaderboard.
|
||||||
|
* @return a JSON object of the friendlist with only names and scores.
|
||||||
|
*/
|
||||||
public String friendsToString(){
|
public String friendsToString(){
|
||||||
String result = "friends=[";
|
String result = "friends=[";
|
||||||
for(User u : friends){
|
for (User u : friends) {
|
||||||
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
|
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
|
||||||
}
|
}
|
||||||
if(result.endsWith(", ")){
|
if (result.endsWith(", ")) {
|
||||||
return result.substring(0, result.lastIndexOf(",")) + "]";
|
return result.substring(0, result.lastIndexOf(",")) + "]";
|
||||||
}
|
}
|
||||||
return result + "]";
|
return result + "]";
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class UserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFriendEmpty(){
|
public void getFriendEmpty() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "merel", "password");
|
User second = new User(1L, "merel", "password");
|
||||||
assertEquals(first.getFriends(), second.getFriends());
|
assertEquals(first.getFriends(), second.getFriends());
|
||||||
@@ -92,7 +92,7 @@ public class UserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addFriendTest(){
|
public void addFriendTest() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "merel", "password");
|
User second = new User(1L, "merel", "password");
|
||||||
assertEquals(first.getFriends(), second.getFriends());
|
assertEquals(first.getFriends(), second.getFriends());
|
||||||
@@ -103,7 +103,7 @@ public class UserTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addYourselfTest(){
|
public void addYourselfTest() {
|
||||||
User test = new User(1L, "greenify", "password");
|
User test = new User(1L, "greenify", "password");
|
||||||
assertEquals(test.getFriends(), new ArrayList<User>());
|
assertEquals(test.getFriends(), new ArrayList<User>());
|
||||||
assertThrows(ApplicationException.class, () -> {
|
assertThrows(ApplicationException.class, () -> {
|
||||||
@@ -113,7 +113,7 @@ public class UserTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void friendsToStringTest(){
|
public void friendsToStringTest() {
|
||||||
User first = new User(1L, "greenify", "password");
|
User first = new User(1L, "greenify", "password");
|
||||||
User second = new User(1L, "merel", "password");
|
User second = new User(1L, "merel", "password");
|
||||||
first.addFriend(second);
|
first.addFriend(second);
|
||||||
|
|||||||
@@ -49,7 +49,8 @@ public class UserServiceTest {
|
|||||||
.thenReturn(alex);
|
.thenReturn(alex);
|
||||||
User lola = new User(2L, "lola", "password");
|
User lola = new User(2L, "lola", "password");
|
||||||
when(userRepository.findByName(lola.getName()))
|
when(userRepository.findByName(lola.getName()))
|
||||||
.thenReturn(lola); }
|
.thenReturn(lola);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validLoginTest() {
|
public void validLoginTest() {
|
||||||
|
|||||||
Reference in New Issue
Block a user