Fix checkstyle errors

This commit is contained in:
Merel Steenbergen
2019-03-26 11:24:10 +01:00
parent 4a6d4c7043
commit f39aef31d0
3 changed files with 23 additions and 20 deletions

View File

@@ -7,16 +7,11 @@ import lombok.Data;
import java.util.HashMap;
import java.util.Map;
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.validation.constraints.NotNull;
@Entity
@@ -27,7 +22,6 @@ public class User {
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
// @Column(name = "id")
private Long id;
@NotNull
@@ -114,15 +108,19 @@ public class User {
this.footPrintInputs = footPrintInputs;
}
public ArrayList<User> getFriends(){
public ArrayList<User> getFriends() {
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");
}
else{
else {
friends.add(user);
System.out.print("Friend added!");
}
@@ -143,12 +141,16 @@ public class User {
+ 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(){
String result = "friends=[";
for(User u : friends){
for (User u : friends) {
result += "{name=" + u.getName() + ", footprint=" + u.getFootPrint() + "}, ";
}
if(result.endsWith(", ")){
if (result.endsWith(", ")) {
return result.substring(0, result.lastIndexOf(",")) + "]";
}
return result + "]";

View File

@@ -84,7 +84,7 @@ public class UserTest {
}
@Test
public void getFriendEmpty(){
public void getFriendEmpty() {
User first = new User(1L, "greenify", "password");
User second = new User(1L, "merel", "password");
assertEquals(first.getFriends(), second.getFriends());
@@ -92,7 +92,7 @@ public class UserTest {
}
@Test
public void addFriendTest(){
public void addFriendTest() {
User first = new User(1L, "greenify", "password");
User second = new User(1L, "merel", "password");
assertEquals(first.getFriends(), second.getFriends());
@@ -103,7 +103,7 @@ public class UserTest {
}
@Test
public void addYourselfTest(){
public void addYourselfTest() {
User test = new User(1L, "greenify", "password");
assertEquals(test.getFriends(), new ArrayList<User>());
assertThrows(ApplicationException.class, () -> {
@@ -113,7 +113,7 @@ public class UserTest {
@Test
public void friendsToStringTest(){
public void friendsToStringTest() {
User first = new User(1L, "greenify", "password");
User second = new User(1L, "merel", "password");
first.addFriend(second);

View File

@@ -49,7 +49,8 @@ public class UserServiceTest {
.thenReturn(alex);
User lola = new User(2L, "lola", "password");
when(userRepository.findByName(lola.getName()))
.thenReturn(lola); }
.thenReturn(lola);
}
@Test
public void validLoginTest() {