Fix checkstyle errors

This commit is contained in:
cugurlu
2019-03-17 17:08:46 +01:00
parent f5fa03b104
commit 07c76dd385
18 changed files with 577 additions and 462 deletions

View File

@@ -10,6 +10,8 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import java.io.IOException;
@SpringBootApplication
public class Application extends javafx.application.Application {
private static ConfigurableApplicationContext springContext;
@@ -19,16 +21,16 @@ public class Application extends javafx.application.Application {
launch(args);
}
public static Parent load(java.net.URL url) {
/**
* This method takes an url and return a parent.
* @param url which is being loaded.
* @return parent object.
*/
public static Parent load(java.net.URL url) throws IOException {
FXMLLoader loader = new FXMLLoader();
loader.setControllerFactory(springContext::getBean);
loader.setLocation(url);
try {
return loader.load();
} catch (Exception e) {
e.printStackTrace();
}
return null;
return loader.load();
}
@Override

View File

@@ -17,17 +17,17 @@ public class DashBoardController {
private int count = 0;
@FXML
public AnchorPane menuBar;
public AnchorPane dashboardPane;
public AnchorPane userPane;
public AnchorPane activitiesPane;
public Label welcomebacktext;
public Button dashboardButton;
public Button activitiesButton;
public Button userButton;
public Button veganMealButton;
public Label counter;
public Label scoreField;
private AnchorPane menuBar;
private AnchorPane dashboardPane;
private AnchorPane userPane;
private AnchorPane activitiesPane;
private Label welcomebacktext;
private Button dashboardButton;
private Button activitiesButton;
private Button userButton;
private Button veganMealButton;
private Label counter;
private Label scoreField;
/**
* displays the dashboard pane.
@@ -70,7 +70,8 @@ public class DashBoardController {
count++;
counter.setText("Count: " + count);
System.out.println(userService);
userService.addVeganMeal(userService.currentUser.getId(), userService.currentUser.getName());
userService.addVeganMeal(userService.currentUser.getId(),
userService.currentUser.getName());
System.out.println("Vegetarian meal is added");
}
}

View File

@@ -33,7 +33,7 @@ public class RegisterWindowController {
*/
@FXML
public void handleSignUpButton(ActionEvent event) {
//set the window to the current window (for displaying the alerts)
//set the window to the current window (for displaying the alerts)
Window owner = signupButton.getScene().getWindow();
//check if the username field is empty
if (userNameText.getText().isEmpty()) {

View File

@@ -4,7 +4,6 @@ import greenify.client.Application;
import greenify.client.rest.UserService;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
@@ -24,15 +23,9 @@ public class UserController {
UserService userService;
@FXML
public TextField usernameField;
@FXML
private TextField usernameField;
private PasswordField passwordField;
@FXML
private Button loginButton;
@FXML
private Button signupButton;
@FXML
@@ -65,9 +58,11 @@ public class UserController {
* @author sem
*/
public void openDashboard() throws IOException {
Parent dash = Application.load (this.getClass().getClassLoader().getResource("fxml/dashboard.fxml"));
Parent dash = Application.load(this.getClass().getClassLoader()
.getResource("fxml/dashboard.fxml"));
Scene scene = new Scene(dash);
scene.getStylesheets().add(getClass().getClassLoader().getResource("stylesheets/dashboardStyle.css").toExternalForm());
scene.getStylesheets().add(getClass().getClassLoader()
.getResource("stylesheets/dashboardStyle.css").toExternalForm());
Stage appStage = new Stage();
appStage.setScene(scene);
appStage.show();
@@ -94,13 +89,16 @@ public class UserController {
}
}
public void handleRegisterButtonAction(ActionEvent event) throws Exception{
//load the fxml file
Parent registerWindow = Application.load (this.getClass().getClassLoader().getResource("fxml/RegisterWindow.fxml"));
//make the window use the scene
/**
* The method handles register button.
* @param event User clicks to the button
* @throws Exception when the file couldn't find
*/
public void handleRegisterButtonAction(ActionEvent event) throws Exception {
Parent registerWindow = Application.load(this.getClass().getClassLoader()
.getResource("fxml/RegisterWindow.fxml"));
Scene registerScene = new Scene(registerWindow);
Stage registerStage = new Stage();
//open the window
registerStage.setScene(registerScene);
registerStage.setTitle("Enter register credentials");
registerStage.show();

View File

@@ -1,11 +1,12 @@
package greenify.client.rest;
import greenify.common.UserDTO;
import greenify.common.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
@@ -15,7 +16,7 @@ public class UserService {
@Autowired
RestTemplate restTemplate;
public UserDTO currentUser;
public UserDto currentUser;
@Bean
RestTemplate restTemplate(RestTemplateBuilder builder) {
@@ -28,7 +29,7 @@ public class UserService {
* @param password the password of the user
* @return a userDTO
*/
public UserDTO registerUser(String name, String password) {
public UserDto registerUser(String name, String password) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser")
@@ -36,7 +37,8 @@ public class UserService {
.queryParam("password", password);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
UserDTO result = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
UserDto result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), UserDto.class);
this.currentUser = result;
return result;
}
@@ -47,7 +49,7 @@ public class UserService {
* @param password the password of the user
* @return a userDTO
*/
public UserDTO loginUser(String name, String password) {
public UserDto loginUser(String name, String password) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/loginUser")
@@ -55,7 +57,8 @@ public class UserService {
.queryParam("password", password);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
UserDTO result = this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
UserDto result = this.restTemplate.getForObject(builder.build()
.encode().toUri(), UserDto.class);
this.currentUser = result;
return result;
}
@@ -66,7 +69,7 @@ public class UserService {
* @param name the username of the user
* @return a userDTO
*/
public UserDTO addVeganMeal(Long id, String name) {
public UserDto addVeganMeal(Long id, String name) {
HttpHeaders headers = new HttpHeaders();
headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/addVeganMeal")
@@ -74,6 +77,6 @@ public class UserService {
.queryParam("name", name);
HttpEntity<?> entity = new HttpEntity<>(headers);
System.out.println(builder.build().encode().toUri());
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);
return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDto.class);
}
}

View File

@@ -1,9 +1,12 @@
import greenify.client.rest.UserService;
import greenify.common.UserDTO;
import greenify.common.UserDto;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.*;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,32 +25,32 @@ public class UserServiceTest {
@Test
public void userRegisterTest() throws Exception {
UserDTO testUser = new UserDTO(1L, "Eric");
UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/registerUser?name=Eric&password=password"),
UserDTO.class))
UserDto.class))
.thenReturn(testUser);
UserDTO user = userService.registerUser("Eric", "password");
UserDto user = userService.registerUser("Eric", "password");
Assert.assertEquals(testUser, user);
}
@Test
public void userLoginTest() throws Exception {
UserDTO testUser = new UserDTO(1L, "Eric");
UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/loginUser?name=Eric&password=password"),
UserDTO.class))
UserDto.class))
.thenReturn(testUser);
UserDTO user = userService.loginUser("Eric", "password");
UserDto user = userService.loginUser("Eric", "password");
Assert.assertEquals(testUser, user);
}
@Test
public void addVeganMealTest() throws Exception {
UserDTO testUser = new UserDTO(1L, "Eric");
UserDto testUser = new UserDto(1L, "Eric");
Mockito.when(restTemplate.getForObject(new java.net.URI("http://localhost:8080/addVeganMeal?id=1&name=Eric"),
UserDTO.class))
UserDto.class))
.thenReturn(testUser);
UserDTO user = userService.addVeganMeal(1L, "Eric");
UserDto user = userService.addVeganMeal(1L, "Eric");
Assert.assertEquals(testUser, user);
}
}