From daa1c838b4d482d50ad839eec0bfab71009833e2 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 17:00:45 +0200 Subject: [PATCH 1/6] EDIT::Change some hints and add tests --- .../src/main/java/greenify/client/Hints.java | 57 ++++++++++--------- src/Client/src/test/java/HintsTest.java | 17 +++++- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index b9fda77..63277ad 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -16,50 +16,51 @@ public class Hints { */ 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!"); + + "footprint, but it will 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."); + + "to cook? And an electric oven is not much better at 12%!"); + this.hints.add("70% of the deforestation of the Amazon rainforest 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, " + + " 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("Did you know? The carbon footprint of a vegetarian diet is about half " + this.hints.add("The carbon footprint of a vegetarian diet is about half " + "that of a meat-lover’s diet!"); - this.hints.add("Cycling is good for the environment AND for your body, " + 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 sun’s 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."); + + "hour, we could power the entire world for one whole year!"); + this.hints.add("27,000 trees are cut down every day so we can have toilet paper."); + this.hints.add("Recycle glass bottles! A glass bottle made now 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?"); - this.hints.add("Reuse your bags when you go grocery shopping. You will save plastic bags!"); + + " you're not using at the moment. Save some energy!"); + this.hints.add("Did you know that about 4,5% of the Dutch population does not eat meat?"); + this.hints.add("Reuse your bags when you go grocery shopping. You will save " + + "plastic bags and won't have a lot of unused bags at home!"); this.hints.add("An estimated 250 million trees can be saved each year " - + "if every published newspaper would be recycled."); - this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector."); - this.hints.add("You can use LED lights in your home to save energy!"); + + "if every published newspaper would be recycled!"); + this.hints.add("About 88,000 jobs were created in 2015 through the wind power sector. " + + "That is a lot of jobs"); + this.hints.add("You can use LED lights in your home to save energy! " + + "They make light from about 85% of their energy"); this.hints.add("If you isolate your home well, it will be warmer, " - + "and you'll save energy as well!"); + + "and you'll save energy as well! No need to wear sweaters anymore"); this.hints.add("Do you have leftovers? Donate them to food kitchens." + " This way you won't waste" - + " food, and you'll help people at the same time!"); + + " food, and you'll help a lot of people at the same time!"); this.hints.add("A lot of coffee places give you a discount if you bring your own cup. " - + "Get rid of those disposable cups!"); + + "Get rid of disposable cups!"); this.hints.add("When shopping, look for products with minimal to no packaging, " - + "or at least packaging made from recycled items. "); + + "or packaging made from recycled items. "); this.hints.add("If you order food, you can ask the restaurant to not include " - + "utensils and napkins, it saves plastic and paper."); - this.hints.add("It takes about 66 days to form a new habit, keep going!"); + + "utensils and napkins, it saves plastic and paper!"); + this.hints.add("It takes about 66 days to form a new habit, keep going, you'll get there!"); this.hints.add("Get yourself a nice reusable water bottle! It's cheaper and better for " - + "the environment to refill than to buy a new one every time it's empty."); - this.hints.add("Recycle glass bottles!" - + " A glass bottle made in our time will take more than 4,000 years" - + " to decompose."); - this.hints.add("Only 1% of our planet’s water supply can be used." + + "the environment to refill than to buy one every time it's empty."); + this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater." + " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); - this.hints.add("Plastic bad"); + this.hints.add("Plastic bad, very bad."); } /** diff --git a/src/Client/src/test/java/HintsTest.java b/src/Client/src/test/java/HintsTest.java index c0e2442..5964852 100644 --- a/src/Client/src/test/java/HintsTest.java +++ b/src/Client/src/test/java/HintsTest.java @@ -1,5 +1,6 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import greenify.client.Hints; import org.junit.Test; @@ -15,7 +16,7 @@ public class HintsTest { public void hintsContainsTest() { Hints test = new Hints(); assertTrue(test.hints.contains("27,000 trees are cut down " - + "each day so we can have toilet paper.")); + + "every day so we can have toilet paper.")); } @Test @@ -24,6 +25,20 @@ public class HintsTest { String random = test.randomHint(); assertTrue(test.hints.contains(random)); } + + @Test + public void hintsContainsTestTwo() { + Hints test = new Hints(); + assertTrue(test.hints.contains("Plastic bad, very bad.")); + } + + + @Test + public void hintsNotNullTest() { + Hints test = new Hints(); + assertNotNull(test.hints); + } + } From 67b97eb331baa3e5368efd7bf2eb050e5a2d9440 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 17:08:58 +0200 Subject: [PATCH 2/6] FIXX:: Checkstyle --- .../src/main/java/greenify/client/Hints.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 63277ad..a3aa74c 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -19,17 +19,18 @@ public class Hints { + "footprint, but it will 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 rainforest 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("70% of the deforestation of the Amazon rainforest 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("The carbon footprint of a vegetarian diet is about half " + "that of a meat-lover’s 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 sun’s energy shining on the Earth for just one " - + "hour, we could power the entire world for one whole year!"); + this.hints.add("If we could capture all of the sun’s energy shining on the Earth for just " + + "one hour, we could power the entire world for one whole year!"); this.hints.add("27,000 trees are cut down every day so we can have toilet paper."); this.hints.add("Recycle glass bottles! A glass bottle made now will take " + "more than 4,000 years to decompose."); @@ -60,6 +61,11 @@ public class Hints { + "the environment to refill than to buy one every time it's empty."); this.hints.add("Only 1% of our planet’s water supply can be used a drinkwater." + " 97% is ocean water and 2% is frozen solid in the Arctic, for now."); + this.hints.add("For every two million tons of paper and glass, collected in " + + "the Netherlands, close to 90% gets recycled and used to make new products"); + this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household " + + "equipment, you will automatically be charged a ‘recycling tax’ on it. This is " + + "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch"); this.hints.add("Plastic bad, very bad."); } From b92e302f8bf6dc56622d0f08be7a70542dde64e5 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:11:51 +0200 Subject: [PATCH 3/6] ADD::Extra hints --- src/Client/src/main/java/greenify/client/Hints.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index a3aa74c..8e14d74 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -66,6 +66,15 @@ public class Hints { this.hints.add("In the Netherlands: Whenever you purchase any new, electronic or household " + "equipment, you will automatically be charged a ‘recycling tax’ on it. This is " + "also known as ‘removal tax’, or ‘verwijderingsbijdrage’ in Dutch"); + this.hints.add("Second only to Germany, the Netherlands leads the world in recycling" + + ", with 65 percent of all waste recycled."); + this.hints.add("If tbe back of your fridge is dusty, it can increase " + + "energy consumption by 30 per cent."); + this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and" + + " lead to increased pollution and higher greenhouse gas emissions."); + this.hints.add("Meat production is extremely resource-intensive. " + +"If you gave it up just once a week, you would save the 840 gallons " + + "of fresh water it takes to produce a single serving."); this.hints.add("Plastic bad, very bad."); } From 02253cb6458711b7d03381ee6994458016b27778 Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:16:26 +0200 Subject: [PATCH 4/6] FIX::Checkstyle errors --- src/Client/src/main/java/greenify/client/Hints.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 8e14d74..5e03535 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -73,13 +73,13 @@ public class Hints { this.hints.add("Underinflated tyres decrease fuel economy by up to three percent and" + " lead to increased pollution and higher greenhouse gas emissions."); this.hints.add("Meat production is extremely resource-intensive. " - +"If you gave it up just once a week, you would save the 840 gallons " + + "If you gave it up just once a week, you would save the 840 gallons " + "of fresh water it takes to produce a single serving."); this.hints.add("Plastic bad, very bad."); } /** - * This method returns a random String. + * This method returns an arbitrary String. * @return the random hint. */ public String randomHint() { From 47c46b54589a5c71842c657f1cfab8025ea0f9ea Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:20:09 +0200 Subject: [PATCH 5/6] FIX::More CS errors --- src/Client/src/main/java/greenify/client/Hints.java | 4 ++-- .../java/greenify/client/controller/DashBoardController.java | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/Hints.java b/src/Client/src/main/java/greenify/client/Hints.java index 5e03535..2319cae 100644 --- a/src/Client/src/main/java/greenify/client/Hints.java +++ b/src/Client/src/main/java/greenify/client/Hints.java @@ -79,8 +79,8 @@ public class Hints { } /** - * This method returns an arbitrary String. - * @return the random hint. + * This seeks out a random hint from the list of strings. + * @return the random string hint. */ public String randomHint() { Random rand = new Random(); diff --git a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java index 6ce8230..ac9b27d 100644 --- a/src/Client/src/main/java/greenify/client/controller/DashBoardController.java +++ b/src/Client/src/main/java/greenify/client/controller/DashBoardController.java @@ -426,6 +426,9 @@ public class DashBoardController { calcStage.show(); } + /** + * This method adds a random hint to the GUI. + */ public void addRandomHints() { FadeTransition fadeOut = new FadeTransition(Duration.millis(400), hintText); fadeOut.setFromValue(1.0); From 9ab4439f708eda78985d0563c9f8c16ebd0adfbf Mon Sep 17 00:00:00 2001 From: Merel Steenbergen Date: Fri, 5 Apr 2019 19:34:08 +0200 Subject: [PATCH 6/6] FIX::Illegal catch fix: RuntimeException to HttpClientErrorException --- .../greenify/client/controller/RegisterWindowController.java | 4 ++-- .../main/java/greenify/client/controller/UserController.java | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java index 9ecad09..c84e8e8 100644 --- a/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java +++ b/src/Client/src/main/java/greenify/client/controller/RegisterWindowController.java @@ -29,6 +29,7 @@ import javafx.stage.Window; import javafx.util.Duration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.text.DecimalFormat; @@ -230,8 +231,7 @@ public class RegisterWindowController { //register the user with the provided username and password try { userService.registerUser(userNameText.getText(), passwordField.getText()); - } - catch (RuntimeException ex) { + } catch (HttpClientErrorException ex) { UserController.AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Username Error!", "This username has already been taken!"); return; diff --git a/src/Client/src/main/java/greenify/client/controller/UserController.java b/src/Client/src/main/java/greenify/client/controller/UserController.java index 19af71a..4dffbdd 100644 --- a/src/Client/src/main/java/greenify/client/controller/UserController.java +++ b/src/Client/src/main/java/greenify/client/controller/UserController.java @@ -2,6 +2,7 @@ package greenify.client.controller; import greenify.client.Application; import greenify.client.rest.UserService; +import greenify.common.ApplicationException; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.Parent; @@ -14,6 +15,7 @@ import javafx.stage.Stage; import javafx.stage.Window; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.client.HttpClientErrorException; import java.io.IOException; import java.util.Objects; @@ -67,8 +69,7 @@ public class UserController { //log the user in with the userService method try { userService.loginUser(usernameField.getText(), passwordField.getText()); - } - catch (RuntimeException ex) { + } catch (HttpClientErrorException ex) { AlertHelper.showAlert(Alert.AlertType.ERROR, owner, "Log-in Error!", "Your username or password is incorrect!"); return;