Merge branch 'update/achievements' into 'master'

Update/achievements

See merge request cse1105/2018-2019/oopp-group-43/template!68
This commit is contained in:
Sem van der Hoeven
2019-04-06 17:20:49 +00:00
12 changed files with 349 additions and 212 deletions

View File

@@ -12,26 +12,28 @@ public class Hints {
}
/**
* This method adds all the Strings to the arraylist.
* This method adds all the Strings to the array list.
*/
private void initHints() {
this.hints.add("Buying local produce will not only decrease your carbon "
+ "footprint, but also help your local economy: A win-win!");
this.hints.add("Did you know that a gas oven only uses 6% of its energy "
+ "to cook? And an electric oven is not much better at 12%.");
this.hints.add("70% of the deforestation of the Amazon is to provide land for cattle ranches.");
this.hints.add("70% of the deforestation of the Amazon is to provide land for "
+ "cattle ranches.");
this.hints.add("Research shows that reducing meat consumption can increase"
+ " your life span by 3.6 years");
this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood pressure, "
+ "diabetes and cancer than meat eaters.");
this.hints.add("Vegetarians have a lower risk of getting heart disease, high blood "
+ "pressure, diabetes and cancer than meat eaters.");
this.hints.add("Did you know? The carbon footprint of a vegetarian diet is about half "
+ "that of a meat-lovers diet!");
this.hints.add("Cycling is good for the environment AND for your body, "
+ "so why not grab your bike instead of your car?");
this.hints.add("If we could capture all of the suns energy shining on the Earth for just one "
+ "hour, we could power the entire world for one year!");
this.hints.add("If we could capture all of the suns energy shining on the Earth"
+ " for just one hour, we could power the entire world for one year!");
this.hints.add("27,000 trees are cut down each day so we can have toilet paper.");
this.hints.add("A glass bottle made in our time will take more than 4,000 years to decompose.");
this.hints.add("A glass bottle made in our time will take more than 4,000 years "
+ "to decompose.");
this.hints.add("Don't forget to turn off the lights and heating in rooms"
+ " you're not using at the moment!");
this.hints.add("Did you know that about 4.5% of the Dutch population does not eat meat?");
@@ -63,7 +65,7 @@ public class Hints {
}
/**
* This method returns a random String.
* This method gets a random String.
* @return the random hint.
*/
public String randomHint() {

View File

@@ -394,6 +394,128 @@ public class CalculatorController {
userService.updateInput(userService.currentUser.getName(), "input_size",
peopleInHouseHoldLabel.getText());
}
checkTransportLabels();
checkHousingLabels();
checkFoodLabels();
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
checkCheckBoxes();
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
controller.updateLeaderboard();
CalculatorController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
owner, "Footprint saved!", "Your footprint is saved!");
}
/**
* Checks the check boxes.
*/
public void checkCheckBoxes() {
if (localProduceCheckbox.isSelected()) {
localProduceCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"local_produce", true);
}
if (bikeCheckbox.isSelected()) {
bikeCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"bike", true);
}
if (temperatureCheckbox.isSelected()) {
temperatureCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"temperature", true);
}
if (solarPanelsCheckbox.isSelected()) {
solarPanelsCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels", true);
}
}
/**
* Checks the food labels.
*/
public void checkFoodLabels() {
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
}
/**
* Checks the housing labels.
*/
public void checkHousingLabels() {
if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars",
electricityField.getText());
}
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_gco2_per_kwh",
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
}
if (!naturalGasField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_naturalgas_dollars",
naturalGasField.getText());
}
if (!heatingOilField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_heatingoil_dollars",
heatingOilField.getText());
}
if (!livingSpaceField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_squarefeet",
livingSpaceField.getText());
}
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_watersewage",
waterUsageLabel.getText().replace("% of similar households", ""));
}
}
/**
* Checks the transport labels.
*/
public void checkTransportLabels() {
if (!publicTransitField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_publictrans",
@@ -434,99 +556,5 @@ public class CalculatorController {
"input_footprint_transportation_mpg3",
carTravelElectricLabel.getText().replace(" mpge", ""));
}
if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars",
electricityField.getText());
}
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_gco2_per_kwh",
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
}
if (!naturalGasField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_naturalgas_dollars",
naturalGasField.getText());
}
if (!heatingOilField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_heatingoil_dollars",
heatingOilField.getText());
}
if (!livingSpaceField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_squarefeet",
livingSpaceField.getText());
}
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_watersewage",
waterUsageLabel.getText().replace("% of similar households", ""));
}
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
if (localProduceCheckbox.isSelected()) {
localProduceCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"local_produce", true);
}
if (bikeCheckbox.isSelected()) {
bikeCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"bike", true);
}
if (temperatureCheckbox.isSelected()) {
temperatureCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"temperature", true);
}
if (solarPanelsCheckbox.isSelected()) {
solarPanelsCheckbox.setSelected(true);
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels", true);
}
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
controller.updateLeaderboard();
CalculatorController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION,
owner, "Footprint saved!", "Your footprint is saved!");
}
}

View File

@@ -420,6 +420,13 @@ public class DashBoardController {
current.close();
System.out.println("User is logged out");
//global leaderboard
globalLeaderboard.getItems().clear();
globalLeaderData.removeAll();
//development leaderboard
developmentLeaderboard.getItems().clear();
developmentData.removeAll();
//load the fxml file
Parent dash = Application.load(this.getClass().getClassLoader()
.getResource("fxml/LoginWindow.fxml"));
@@ -457,6 +464,9 @@ public class DashBoardController {
calcStage.show();
}
/**
* Adds a random hint to the left.
*/
public void addRandomHints() {
FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText);
fadeOut.setFromValue(1.0);

View File

@@ -230,8 +230,7 @@ public class RegisterWindowController {
//register the user with the provided username and password
try {
userService.registerUser(userNameText.getText(), passwordField.getText());
}
catch (RuntimeException ex) {
} catch (RuntimeException ex) {
UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!",
"This username has already been taken!");
return;
@@ -456,6 +455,115 @@ public class RegisterWindowController {
userService.updateInput(userService.currentUser.getName(), "input_size",
peopleInHouseHoldLabel.getText());
}
checkTransportLabels();
checkHousingLabels();
checkFoodLabels();
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
if (localProduceCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"local_produce", true);
}
if (bikeCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"bike", true);
}
if (temperatureCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"temperature", true);
}
if (solarPanelsCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels", true);
}
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
}
/**
* Checks the food labels.
*/
public void checkFoodLabels() {
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
}
/**
* Checks the housing labels.
*/
public void checkHousingLabels() {
if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars",
electricityField.getText());
}
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_gco2_per_kwh",
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
}
if (!naturalGasField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_naturalgas_dollars",
naturalGasField.getText());
}
if (!heatingOilField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_heatingoil_dollars",
heatingOilField.getText());
}
if (!livingSpaceField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_squarefeet",
livingSpaceField.getText());
}
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_watersewage",
waterUsageLabel.getText().replace("% of similar households", ""));
}
}
/**
* Checks the transport labels.
*/
public void checkTransportLabels() {
if (!publicTransitField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_transportation_publictrans",
@@ -496,93 +604,5 @@ public class RegisterWindowController {
"input_footprint_transportation_mpg3",
carTravelElectricLabel.getText().replace(" mpge", ""));
}
if (!electricityField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_electricity_dollars",
electricityField.getText());
}
if (!cleanEnergyPurchasedLabel.getText().replace(" %", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_gco2_per_kwh",
cleanEnergyPurchasedLabel.getText().replace(" %", ""));
}
if (!naturalGasField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_naturalgas_dollars",
naturalGasField.getText());
}
if (!heatingOilField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_heatingoil_dollars",
heatingOilField.getText());
}
if (!livingSpaceField.getText().equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_squarefeet",
livingSpaceField.getText());
}
if (!waterUsageLabel.getText().replace("% of similar households", "").equals("0")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_housing_watersewage",
waterUsageLabel.getText().replace("% of similar households", ""));
}
if (!meatFishEggsLabel.getText().replace(" daily servings per person", "").equals("2.6")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_meatfisheggs",
meatFishEggsLabel.getText().replace(" daily servings per person", ""));
}
if (!grainsBakedGoodsLabel.getText()
.replace(" daily servings per person", "").equals("4.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_cereals",
grainsBakedGoodsLabel.getText().replace(" daily servings per person", ""));
}
if (!dairyLabel.getText().replace(" daily servings per person", "").equals("2.4")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_dairy",
dairyLabel.getText().replace(" daily servings per person", ""));
}
if (!fruitsVegetablesLabel.getText()
.replace(" daily servings per person", "").equals("3.9")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_fruitvegetables",
fruitsVegetablesLabel.getText().replace(" daily servings per person", ""));
}
if (!snacksDrinksLabel.getText().replace(" daily servings per person", "").equals("3.7")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_food_otherfood",
snacksDrinksLabel.getText().replace(" daily servings per person", ""));
}
if (!goodsLabel.getText().replace(" € / month", "").equals("1520")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_goods_total",
goodsLabel.getText().replace("€ / month", ""));
}
if (!servicesLabel.getText().replace(" € / month", "").equals("3428")) {
userService.updateInput(userService.currentUser.getName(),
"input_footprint_shopping_services_total",
servicesLabel.getText().replace("€ / month", ""));
}
if (localProduceCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"local_produce", true);
}
if (bikeCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"bike", true);
}
if (temperatureCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"temperature", true);
}
if (solarPanelsCheckbox.isSelected()) {
userService.updateExtraInput(userService.currentUser.getName(),
"solar_panels", true);
}
Float firstFootprint = userService.saveFirstFootprint(userService.currentUser.getName());
Float footprint = userService.saveFootprint(userService.currentUser.getName());
Window owner = saveButton.getScene().getWindow();
Stage current = (Stage) owner;
current.close();
}
}

View File

@@ -67,8 +67,7 @@ public class UserController {
//log the user in with the userService method
try {
userService.loginUser(usernameField.getText(), passwordField.getText());
}
catch (RuntimeException ex) {
} catch (RuntimeException ex) {
AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!",
"Your username or password is incorrect!");
return;

View File

@@ -54,6 +54,7 @@
<Line endX="104.0" layoutX="109.0" layoutY="223.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Line fx:id="pathLine" endX="100.0" endY="28.0" fill="#1b9736" layoutX="8.0" layoutY="323.0" startX="-100.0" startY="28.0" stroke="#5a635c" />
<Line endX="104.0" layoutX="105.0" layoutY="271.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" />
<Line endX="104.0" layoutX="106.0" layoutY="270.0" startX="-100.0" stroke="#e3ffe8" strokeWidth="0.7" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
<Label fx:id="hintText" alignment="TOP_LEFT" layoutX="14.0" layoutY="420.0" prefHeight="218.0" prefWidth="187.0" text="Hints" textFill="#c2cdc4">
<font>
<Font size="15.0" />
@@ -474,7 +475,7 @@
<ImageView fx:id="achiev1image" fitHeight="150.0" fitWidth="200.0" layoutX="579.0" layoutY="396.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../achiev1pic.jpg" />
<Image url="@../icons/achiev1pic.jpg" />
<!-- image from shutterstock.com - 1038138760 -->
</image>
</ImageView>

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

@@ -10,7 +10,11 @@ import java.util.Map;
public class AllAchievements {
private static final List<Achievement> allAchievements = Arrays.asList(
new Achievement("Starting off", "You did your first green activity", false),
new Achievement("Social butterfly", "You added three friends", false)
new Achievement("Social butterfly", "You added three friends", false),
new Achievement("Green saver", "You saved * of CO2", false),
new Achievement("Animal friend", "You have eaten 10 vegetarian meals", false),
new Achievement("Tom Dumoulin", "You have biked * km", false),
new Achievement("Let it shine", "You installed solar panels", false)
);
/**

View File

@@ -191,6 +191,8 @@ public class InputValidator {
map.put("bike", false);
map.put("temperature", false);
map.put("solar_panels", false);
map.put("vegetarian", false);
map.put("public_transport", false);
return map;
}
}

View File

@@ -2,7 +2,6 @@ package greenify.server.service;
import greenify.server.InputValidator;
import greenify.server.data.model.User;
import greenify.server.data.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -22,6 +21,10 @@ public class AchievementService {
public void updateAchievements(User user) {
achieveGettingStarted(user);
achieveSocialButterfly(user);
achieveGreenSaver(user);
achieveAnimalFriend(user);
achieveTomDumoulin(user);
achieveLetItShine(user);
}
/**
@@ -36,14 +39,53 @@ public class AchievementService {
}
/**
* This method makes sure the user gets an achievement
* when they have added three friends.
* This method changes achiev2 when this is the case.
* @param user user for whom achiev2 changes
*/
public void achieveSocialButterfly(User user) {
if (user.getFriends().size() == 3) {
if (user.getFriends().size() >= 3) {
userService.setAchievement(user.getName(), "Social butterfly", true);
}
}
/**
* This method changes achiev3 when this is the case.
* @param user user for whom achiev3 changes
*/
public void achieveGreenSaver(User user) {
if (43 - user.getFootPrint() > 38) {
userService.setAchievement(user.getName(), "Green saver", true);
}
}
/**
* This method changes achiev4 when this is the case.
* @param user user for whom achiev4 changes
*/
public void achieveAnimalFriend(User user) {
if (user.getExtraInputs().get("vegetarian")) {
userService.setAchievement(user.getName(), "Animal friend", true);
}
}
/**
* This method changes achiev5 when this is the case.
* @param user user for whom achiev5 changes
*/
public void achieveTomDumoulin(User user) {
if (user.getExtraInputs().get("bike")) {
userService.setAchievement(user.getName(), "Tom Dumoulin", true);
}
}
/**
* This method changes achiev6 when this is the case.
* @param user user for whom achiev6 changes
*/
public void achieveLetItShine(User user) {
if (user.getExtraInputs().get("solar_panels")) {
userService.setAchievement(user.getName(), "Let it shine", true);
}
}
}

View File

@@ -1,12 +1,8 @@
import static org.junit.Assert.assertEquals;
import greenify.server.AllAchievements;
import greenify.server.data.model.Achievement;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
class AllAchievementsTest {
@Test
@@ -19,13 +15,6 @@ class AllAchievementsTest {
@Test
void getDefaultsTest() {
List<Achievement> all = new ArrayList<Achievement>() {{
add(new Achievement(
"Starting off", "You did your first green activity", false));
add(new Achievement(
"Social butterfly", "You added three friends", false));
}
};
assertEquals(all.size(), AllAchievements.getDefaults().size());
assertEquals(6, AllAchievements.getDefaults().size());
}
}

View File

@@ -61,6 +61,7 @@ public class AchievementServiceTest {
User alex = userRepository.findByName("alex");
achievementService.updateAchievements(alex);
assertEquals(true, userService.getAchievement("alex", "Starting off"));
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
}
@Test
@@ -71,4 +72,43 @@ public class AchievementServiceTest {
assertEquals(false, userService.getAchievement("alex", "Social butterfly"));
}
@Test
public void achieveSocialButterflyTest() {
User alex = userRepository.findByName("alex");
alex.addFriend(new User(2L, "Bubbles", "Bubbles"));
alex.addFriend(new User(3L, "Cheese", "crackers"));
alex.addFriend(new User(4L, "Perry", "Doofenshmirtz"));
achievementService.achieveSocialButterfly(alex);
assertEquals(true, userService.getAchievement("alex", "Social butterfly"));
}
@Test
public void achieveGreenSaverTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveGreenSaver(alex);
assertEquals(true, userService.getAchievement("alex", "Green saver"));
}
@Test
public void achieveAnimalFriendTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveAnimalFriend(alex);
assertEquals(false, userService.getAchievement("alex", "Animal friend"));
}
@Test
public void achieveTomDumoulinTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveTomDumoulin(alex);
assertEquals(false, userService.getAchievement("alex", "Tom Dumoulin"));
}
@Test
public void achieveLetItShineTest() {
User alex = userRepository.findByName("alex");
achievementService.achieveLetItShine(alex);
assertEquals(false, userService.getAchievement("alex", "Let it shine"));
}
}