Update methods for extras
This commit is contained in:
@@ -8,20 +8,28 @@ import javafx.beans.value.ChangeListener;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.Slider;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.Window;
|
||||
import javafx.util.Duration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
@Controller
|
||||
public class ExtraActivityController {
|
||||
|
||||
@Autowired
|
||||
UserService userService;
|
||||
|
||||
@Autowired
|
||||
CalculatorController calculatorController;
|
||||
|
||||
@Autowired
|
||||
DashBoardController controller;
|
||||
|
||||
@FXML
|
||||
private AnchorPane veganMealPane;
|
||||
@FXML
|
||||
@@ -59,6 +67,8 @@ public class ExtraActivityController {
|
||||
private Slider solarPanelsSlider;
|
||||
@FXML
|
||||
private Label solarPanelsLabel;
|
||||
@FXML
|
||||
private Button saveButton;
|
||||
|
||||
/**
|
||||
* initializes the sliders and labels before loading.
|
||||
@@ -78,7 +88,6 @@ public class ExtraActivityController {
|
||||
displayBikeButton.setSkin(new TranslateButtonSkin(displayBikeButton));
|
||||
displayTemperatureButton.setSkin(new TranslateButtonSkin(displayTemperatureButton));
|
||||
displaySolarPanelButton.setSkin(new TranslateButtonSkin(displaySolarPanelButton));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,6 +159,43 @@ public class ExtraActivityController {
|
||||
solarPanelPane.setVisible(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* The method updates the values
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void save(ActionEvent event) throws InterruptedException {
|
||||
Window owner = saveButton.getScene().getWindow();
|
||||
Float footprint = userService.saveFootprint(userService.currentUser.getName());
|
||||
controller.updateLeaderboard();
|
||||
Stage current = (Stage) owner;
|
||||
current.close();
|
||||
UserController.AlertHelper.showAlert(Alert.AlertType.CONFIRMATION, owner, "Activities are added!",
|
||||
"Your new activities are added!");
|
||||
}
|
||||
|
||||
/**
|
||||
* The method updates the values of extras.
|
||||
* @param event user clicks to button
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateExtras(ActionEvent event) throws InterruptedException {
|
||||
if (!bikeLabel.getText().replace(" km", "").equals("0")) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike",
|
||||
bikeLabel.getText().replace(" km", ""));
|
||||
}
|
||||
if (!solarPanelsLabel.getText().equals("0")) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"solar_panels",
|
||||
solarPanelsLabel.getText());
|
||||
}
|
||||
if (!temperatureLabel.getText().replace(" Degrees", "").equals("0")) {
|
||||
userService.updateExtraInput(userService.currentUser.getName(),
|
||||
"bike",
|
||||
temperatureLabel.getText().replace(" Degrees", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TranslateButtonSkin extends ButtonSkin {
|
||||
/**
|
||||
* button skin that sets a translate animation on entering and exiting the button.
|
||||
|
||||
@@ -109,13 +109,13 @@ public class UserService {
|
||||
* @param value value of the input
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public void updateExtraInput(String name, String inputName, Boolean value) {
|
||||
public void updateExtraInput(String name, String inputName, String value) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/setExtraInput")
|
||||
.queryParam("name", name)
|
||||
.queryParam("inputName", inputName)
|
||||
.queryParam("value",value);
|
||||
.queryParam("value", value);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
ResponseEntity<String> authenticateResponse = this.restTemplate.getForEntity(builder.build()
|
||||
@@ -128,15 +128,16 @@ public class UserService {
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Float getFootprint(String name) {
|
||||
public double getFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFootprint")
|
||||
.queryParam("name", name);
|
||||
new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float result = this.restTemplate.getForObject(builder
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
double result = Math.round(footprint * 10) / 10.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ public class UserService {
|
||||
* @param name name of the user
|
||||
* @return returns the footprint score
|
||||
*/
|
||||
public Float getFirstFootprint(String name) {
|
||||
public double getFirstFootprint(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getFirst")
|
||||
@@ -154,7 +155,8 @@ public class UserService {
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Float footprint = this.restTemplate.getForObject(builder
|
||||
.build().encode().toUri(), Float.class);
|
||||
return footprint;
|
||||
double result = Math.round(footprint * 10) / 10.0;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,14 +272,14 @@ public class UserService {
|
||||
* @param name the username of the current user.
|
||||
*/
|
||||
@SuppressWarnings("Duplicates")
|
||||
public Map<String, Boolean> getExtraInputs(String name) {
|
||||
public Map<String, String> getExtraInputs(String name) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/getExtraInputs")
|
||||
.queryParam("name", name);
|
||||
HttpEntity<?> entity = new HttpEntity<>(headers);
|
||||
System.out.println(builder.build().encode().toUri());
|
||||
Map<String, Boolean> result = this.restTemplate.getForObject(builder.build()
|
||||
Map<String, String> result = this.restTemplate.getForObject(builder.build()
|
||||
.encode().toUri(), Map.class);
|
||||
return result;
|
||||
}
|
||||
@@ -313,4 +315,4 @@ public class UserService {
|
||||
.build().encode().toUri(), List.class);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.ScrollPane?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.control.TextField?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.CalculatorController">
|
||||
<AnchorPane prefHeight="703.0" prefWidth="820.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.RegisterWindowController">
|
||||
<children>
|
||||
<AnchorPane fx:id="calculatorTabs" prefHeight="92.0" prefWidth="820.0" style="-fx-background-color: #677069;">
|
||||
<children>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
@@ -25,7 +24,7 @@
|
||||
<Font size="13.0" />
|
||||
</font>
|
||||
</TextField>
|
||||
<Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" text="Sign up!" textFill="#c4eec9">
|
||||
<Button fx:id="signUpButton" layoutX="115.0" layoutY="229.0" mnemonicParsing="false" onAction="#handleSignUpButton" style="-fx-background-color: #005e07;" text="Sign up!" textFill="#c4eec9">
|
||||
<font>
|
||||
<Font name="Corbel Bold" size="14.0" />
|
||||
</font>
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import java.lang.*?>
|
||||
<?import javafx.scene.chart.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.chart.PieChart?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.CheckBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.TableColumn?>
|
||||
<?import javafx.scene.control.TableView?>
|
||||
@@ -22,7 +14,7 @@
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<AnchorPane prefHeight="702.0" prefWidth="1032.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.DashBoardController">
|
||||
<children>
|
||||
<AnchorPane fx:id="menuBar" prefHeight="703.0" prefWidth="216.0" style="-fx-background-color: #5a635c;">
|
||||
<children>
|
||||
@@ -51,7 +43,7 @@
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="logOutButton" layoutX="48.0" layoutY="644.0" mnemonicParsing="false" onAction="#logOut" prefHeight="45.0" prefWidth="120.0" text="log out ">
|
||||
<Button fx:id="logOutButton" layoutY="270.0" mnemonicParsing="false" onAction="#logOut" prefHeight="45.0" prefWidth="216.0" text="log out ">
|
||||
<font>
|
||||
<Font size="21.0" />
|
||||
</font>
|
||||
@@ -60,6 +52,8 @@
|
||||
<Line endX="104.0" layoutX="105.0" layoutY="178.0" scaleY="0.7" startX="-100.0" stroke="#e3ffe8" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" />
|
||||
<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" />
|
||||
@@ -282,25 +276,25 @@
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="localProduce" layoutX="195.0" layoutY="7.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="18.0" layoutY="39.0" prefHeight="27.0" prefWidth="183.0" text="Using bike">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="bike" layoutX="195.0" layoutY="39.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="71.0" prefHeight="27.0" prefWidth="183.0" text="Lowering the temperature">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="loweringTemp" layoutX="195.0" layoutY="71.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label alignment="CENTER" contentDisplay="CENTER" layoutX="20.0" layoutY="103.0" prefHeight="27.0" prefWidth="183.0" text="Installing solar panels">
|
||||
<font>
|
||||
<Font size="14.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<CheckBox fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
<Label fx:id="solarPanels" layoutX="195.0" layoutY="103.0" mnemonicParsing="false" prefHeight="27.0" prefWidth="55.0" />
|
||||
</children>
|
||||
</Pane>
|
||||
<Button fx:id="addExtraActivityButton2" contentDisplay="RIGHT" layoutX="545.0" layoutY="14.0" mnemonicParsing="false" onAction="#openExtraActivities" style="-fx-background-color: transparent;" text="Add extra activity!" textFill="#147219">
|
||||
@@ -524,4 +518,4 @@
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</AnchorPane>
|
||||
@@ -1,16 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.shape.*?>
|
||||
<?import javafx.scene.text.*?>
|
||||
<?import javafx.scene.image.*?>
|
||||
<?import java.lang.*?>
|
||||
<?import java.util.*?>
|
||||
<?import javafx.scene.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Slider?>
|
||||
<?import javafx.scene.image.Image?>
|
||||
<?import javafx.scene.image.ImageView?>
|
||||
<?import javafx.scene.layout.AnchorPane?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
<?import javafx.scene.shape.Line?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.text.Text?>
|
||||
|
||||
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
|
||||
<AnchorPane prefHeight="611.0" prefWidth="820.0" stylesheets="@../stylesheets/extraActivitiesStyle.css" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="greenify.client.controller.ExtraActivityController">
|
||||
<children>
|
||||
<AnchorPane prefHeight="611.0" prefWidth="107.0">
|
||||
<children>
|
||||
@@ -59,7 +60,7 @@
|
||||
<Font size="20.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addVeganMealButton" contentDisplay="TOP" layoutX="267.0" layoutY="226.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<graphic>
|
||||
<ImageView fitHeight="116.0" fitWidth="156.0" pickOnBounds="true" preserveRatio="true">
|
||||
<image>
|
||||
@@ -87,7 +88,7 @@
|
||||
<Font size="18.0" />
|
||||
</font>
|
||||
</Text>
|
||||
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addBikeButton" contentDisplay="TOP" layoutX="267.0" layoutY="351.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<font>
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
@@ -133,7 +134,7 @@
|
||||
</Label>
|
||||
</children>
|
||||
</HBox>
|
||||
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addTemperatureButton" contentDisplay="TOP" layoutX="267.0" layoutY="353.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<font>
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
@@ -170,7 +171,7 @@
|
||||
</children>
|
||||
</HBox>
|
||||
<Slider fx:id="solarPanelsSlider" blockIncrement="1.0" layoutX="187.0" layoutY="274.0" majorTickUnit="1.0" max="10.0" min="1.0" minorTickCount="0" prefHeight="24.0" prefWidth="338.0" showTickLabels="true" showTickMarks="true" />
|
||||
<Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<Button fx:id="addSolarPanelsButton" contentDisplay="TOP" layoutX="267.0" layoutY="378.0" mnemonicParsing="false" onAction="#updateExtras" prefHeight="150.0" prefWidth="180.0" style="-fx-background-color: transparent;" text="Add activity!" textFill="#23652b">
|
||||
<font>
|
||||
<Font name="System Bold Italic" size="18.0" />
|
||||
</font>
|
||||
@@ -184,5 +185,6 @@
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
<Button fx:id="saveButton" layoutX="30.0" layoutY="30.0" mnemonicParsing="false" prefHeight="36.0" prefWidth="97.0" onAction="#save" text="SAVE!" />
|
||||
</children>
|
||||
</AnchorPane>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import greenify.client.rest.UserService;
|
||||
import greenify.common.UserDto;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
@@ -15,6 +14,9 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UserServiceTest {
|
||||
|
||||
@@ -33,7 +35,7 @@ public class UserServiceTest {
|
||||
.thenReturn(testUser);
|
||||
|
||||
UserDto user = userService.registerUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +45,7 @@ public class UserServiceTest {
|
||||
UserDto.class))
|
||||
.thenReturn(testUser);
|
||||
UserDto user = userService.loginUser("Eric", "password");
|
||||
Assert.assertEquals(testUser, user);
|
||||
assertEquals(testUser, user);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,8 +54,8 @@ public class UserServiceTest {
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFootprint?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
double result = (5 * 10) / 10.0;
|
||||
assertTrue(result == userService.getFootprint("Eric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,8 +64,8 @@ public class UserServiceTest {
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getFirst?name=Eric"),
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.getFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
double result = (5 * 10) / 10.0;
|
||||
assertTrue(result == userService.getFirstFootprint("Eric"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +75,7 @@ public class UserServiceTest {
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,7 +85,7 @@ public class UserServiceTest {
|
||||
Float.class))
|
||||
.thenReturn(estimate);
|
||||
Float result = userService.saveFirstFootprint("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,7 +96,7 @@ public class UserServiceTest {
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getFriendNames("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +107,7 @@ public class UserServiceTest {
|
||||
List.class))
|
||||
.thenReturn(estimate);
|
||||
List<String> result = userService.getAllUsers();
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,18 +118,18 @@ public class UserServiceTest {
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, String> result = userService.getInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getExtraInputsTest() throws Exception {
|
||||
Map<String, Boolean> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", true);
|
||||
Map<String, String> estimate = new HashMap<>();
|
||||
estimate.put("solar_panels", "5");
|
||||
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/getExtraInputs?name=Eric"),
|
||||
Map.class))
|
||||
.thenReturn(estimate);
|
||||
Map<String, Boolean> result = userService.getExtraInputs("Eric");
|
||||
Assert.assertEquals(estimate, result);
|
||||
Map<String, String> result = userService.getExtraInputs("Eric");
|
||||
assertEquals(estimate, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,8 +140,8 @@ public class UserServiceTest {
|
||||
|
||||
@Test
|
||||
public void setExtraInputTest() throws Exception {
|
||||
userService.updateExtraInput("Eric", "solar_panels", true);
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", true);
|
||||
userService.updateExtraInput("Eric", "solar_panels", "8");
|
||||
Mockito.verify(userService).updateExtraInput("Eric", "solar_panels", "8");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user