Fix checkstyle errors and delete unused methods for high coverage

This commit is contained in:
cugurlu
2019-03-31 00:50:21 +01:00
parent cc236c46b6
commit 383d505f52
2 changed files with 130 additions and 150 deletions

View File

@@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class InputValidator { public class InputValidator {
@@ -17,7 +16,7 @@ public class InputValidator {
new InputItem("input_changed", false, "0"), new InputItem("input_changed", false, "0"),
new InputItem("input_footprint_household_adults", false, "0"), new InputItem("input_footprint_household_adults", false, "0"),
new InputItem("input_footprint_household_children", false, "0"), new InputItem("input_footprint_household_children", false, "0"),
new InputItem("input_footprint_transportation_num_vehicles", false, "1"), new InputItem("input_footprint_transportation_num_vehicles", false, "10"),
new InputItem("input_footprint_transportation_miles1", false, "16100", false), new InputItem("input_footprint_transportation_miles1", false, "16100", false),
new InputItem("input_footprint_transportation_mpg1", false, "22", false), new InputItem("input_footprint_transportation_mpg1", false, "22", false),
new InputItem("input_footprint_transportation_fuel1", false, "0", false), new InputItem("input_footprint_transportation_fuel1", false, "0", false),
@@ -96,12 +95,16 @@ public class InputValidator {
new InputItem("input_footprint_shopping_food_dairy", true, "2.2"), new InputItem("input_footprint_shopping_food_dairy", true, "2.2"),
new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"), new InputItem("input_footprint_shopping_food_fruitvegetables", true, "3.5"),
new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"), new InputItem("input_footprint_shopping_food_otherfood", true, "3.4"),
new InputItem("input_footprint_shopping_goods_default_furnitureappliances", false, "1310"), new InputItem("input_footprint_shopping_goods_default_furnitureappliances",
false, "1310"),
new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"), new InputItem("input_footprint_shopping_goods_default_clothing", false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_entertainment", false, "1310"), new InputItem("input_footprint_shopping_goods_default_other_entertainment",
false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"), new InputItem("input_footprint_shopping_goods_default_other_office", false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_personalcare", false, "1310"), new InputItem(
new InputItem("input_footprint_shopping_goods_default_other_autoparts", false, "1310"), "input_footprint_shopping_goods_default_other_personalcare", false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_autoparts",
false, "1310"),
new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"), new InputItem("input_footprint_shopping_goods_default_other_medical", false, "1310"),
new InputItem("input_footprint_shopping_goods_type", false, "1310"), new InputItem("input_footprint_shopping_goods_type", false, "1310"),
new InputItem("input_footprint_shopping_goods_total", false, "1310"), new InputItem("input_footprint_shopping_goods_total", false, "1310"),
@@ -149,7 +152,7 @@ public class InputValidator {
item = inputItem; item = inputItem;
} }
} }
if (Objects.requireNonNull(item).getFloat()) { if (item.getFloat()) {
try { try {
Float.parseFloat(value); Float.parseFloat(value);
} catch (NumberFormatException | NullPointerException nfe) { } catch (NumberFormatException | NullPointerException nfe) {

View File

@@ -5,20 +5,13 @@ import greenify.server.InputValidator;
import lombok.Data; import lombok.Data;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import javax.persistence.ElementCollection; import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
@Entity @Entity
@@ -28,7 +21,7 @@ public class User {
@Id @Id
@NotNull @NotNull
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.TABLE)
private Long id; private Long id;
@NotNull @NotNull
@@ -44,8 +37,7 @@ public class User {
private Map<String, String> footPrintInputs = new HashMap<>(); private Map<String, String> footPrintInputs = new HashMap<>();
@ManyToMany @ManyToMany
@JoinColumn private List<User> friends;
private Collection<User> friends;
public User() {} public User() {}
@@ -147,15 +139,15 @@ public class User {
* This method gets the friends of the user. * This method gets the friends of the user.
* @return friends list of the user * @return friends list of the user
*/ */
public ArrayList<User> getFriends() { public List<User> getFriends() {
return (ArrayList<User>)this.friends; return this.friends;
} }
/** /**
* This method sets the friend list of the user. * This method sets the friend list of the user.
* @param friends friend list of the user * @param friends friend list of the user
*/ */
public void setFriends(Collection<User> friends) { public void setFriends(List<User> friends) {
this.friends = friends; this.friends = friends;
} }
@@ -164,7 +156,7 @@ public class User {
* @param user the friend you want to add. * @param user the friend you want to add.
*/ */
public void addFriend(User user) { public void addFriend(User user) {
if (user.equals(this)) { if (user.equals(this) || friends.contains(user)) {
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);
@@ -182,21 +174,6 @@ 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() {
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 + "]";
}
/** This method checks whether two users are equal or not. /** This method checks whether two users are equal or not.
* * @param other an other user * * @param other an other user
* @return users are (not) equal * @return users are (not) equal