Skip to content

Testing/9 jacoco and unit testing set up #84

Merged
merged 4 commits into from
Apr 24, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# Adrian
.vscode/
.idea/
helpmehelpapplication/target
.target/
.helpmehelpapplication\target/
.helpmehelpapplication\.idea/
1 change: 0 additions & 1 deletion helpmehelpapplication/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.idea/
target/
helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseConnection.java
helpmehelpapplication/src/main/resources/fxml/test/
19 changes: 19 additions & 0 deletions helpmehelpapplication/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.13</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public void start(Stage stage) throws Exception {
new FXMLLoader(HmHApplication.class.getResource("/fxml/frontPage.fxml"));
Scene scene = new Scene(fxmlLoader.load());


BaseController controller = fxmlLoader.getController();
controller.setAuthToken(authToken);

Expand All @@ -43,11 +42,14 @@ public void start(Stage stage) throws Exception {

stage.show();
// Re-enter fullscreen when restored from taskbar
stage.iconifiedProperty().addListener((obs, wasIconified, isNowIconified) -> {
if (!isNowIconified) {
stage.setFullScreen(true);
}
});
stage
.iconifiedProperty()
.addListener(
(obs, wasIconified, isNowIconified) -> {
if (!isNowIconified) {
stage.setFullScreen(true);
}
});
}

@Override
Expand All @@ -71,7 +73,7 @@ public void init() {
APIToDatabaseService db = new APIToDatabaseService(conn);

if (scraper.getAPIScraper().checkConnection()) {
/*
/*
if (scraper.checkConnection()) {
CharityRegistry charityRegistry = scraper.parseJSON(scraper.getJSONData());
for (Charity charity : charityRegistry.getAllCharities()) {
Expand All @@ -80,15 +82,13 @@ public void init() {
*/

// Comment out the two below to use already generated database.
//CharityRegistry charityRegistry = scraper.getAPIAndURLCharityData();
//db.addAPIDataToTable(charityRegistry.getAllCharities());
// CharityRegistry charityRegistry = scraper.getAPIAndURLCharityData();
// db.addAPIDataToTable(charityRegistry.getAllCharities());
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("-- \n Init complete \n --");


}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import ntnu.systemutvikling.team6.controller.components.NavbarController;

public class AboutPageController extends BaseController {
@FXML private NavbarController navbarController;
@FXML private FooterController footerController;
@FXML private NavbarController navbarController;
@FXML private FooterController footerController;

@Override
protected void authTokenisSet() {
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}
@Override
protected void authTokenisSet() {
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import ntnu.systemutvikling.team6.controller.components.*;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.DAO.CharityDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;

Expand All @@ -34,7 +34,7 @@ public class AvailableOrganizationController extends BaseController {
private List<Charity> allCharities;

@Override
protected void authTokenisSet(){
protected void authTokenisSet() {
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}
Expand All @@ -53,8 +53,6 @@ public void initialize() {
CharityRegistry charities = db.getCharitiesFromDB();
allCharities = charities.getAllCharities();



cardsContainer.getChildren().clear();

searchField
Expand Down Expand Up @@ -82,18 +80,17 @@ private List<Charity> filterCharities(String query) {
String name = charity.getName();
String description = charity.getDescription();

if (name == null || name.isBlank()){
if (name == null || name.isBlank()) {
name = "This one has no name";
} else {
name = name.toLowerCase();
}
if (description == null || description.isBlank()){
if (description == null || description.isBlank()) {
description = "This one has no description";
} else {
description = description.toLowerCase();
}


if (name.contains(query) || description.contains(query)) {
matches.add(charity);
}
Expand All @@ -111,7 +108,8 @@ private void displayCharities(List<Charity> charities) {

for (Charity charity : charities) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/components/organizationCard.fxml"));
FXMLLoader loader =
new FXMLLoader(getClass().getResource("/fxml/components/organizationCard.fxml"));
Parent card = loader.load();

OrganizationCardController cardController = loader.getController();
Expand All @@ -138,7 +136,6 @@ public void setInitialSearch(String query) {
searchField.setText(query);
}


/**
* This method is used to switch to the charity page for the selected charity.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package ntnu.systemutvikling.team6.controller;

import javafx.event.ActionEvent;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
Expand Down Expand Up @@ -57,12 +57,11 @@ public class CharityPageController extends BaseController {
public void initialize() {}

@Override
protected void authTokenisSet(){
protected void authTokenisSet() {
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}


private Charity charity;

/**
Expand All @@ -79,11 +78,9 @@ protected void authTokenisSet(){
public void setCharity(Charity charity) {
this.charity = charity;


CharityDescription.setText(charity.getDescription());
CharityName.setText(charity.getName());


if (this.charity.getLogoBlob() != null) {
ByteArrayInputStream logoByteStream = new ByteArrayInputStream(this.charity.getLogoBlob());
Image CharityLogoImage = new Image(logoByteStream);
Expand Down Expand Up @@ -117,8 +114,8 @@ public void setCharity(Charity charity) {
keyValueFormaalLabel.setText(String.format("%.1f%%", numbers.getLast()));
}

// Sets the categories
setCategories(charity.getCategory());
// Sets the categories
setCategories(charity.getCategory());
}

/**
Expand All @@ -144,16 +141,15 @@ public void switchToFrontPage(ActionEvent event) {
* @param event is the event that triggered the search.
*/
@FXML
private void switchToFeedbackPage(ActionEvent event){
private void switchToFeedbackPage(ActionEvent event) {
LoaderScene.LoadScene("giveFeedback", event, charity, null, authToken);

}

/**
* Opens OS default webbrowser and loads the url of the charity on click.
*
* @param event the onclick event
*/
/**
* Opens OS default webbrowser and loads the url of the charity on click.
*
* @param event the onclick event
*/
@FXML
public void handleHomepageClick(ActionEvent event) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,76 +10,77 @@
import ntnu.systemutvikling.team6.controller.components.LoaderScene;
import ntnu.systemutvikling.team6.controller.components.NavbarController;



public class CreateUserPageController extends BaseController {
@FXML
private NavbarController navbarController;
@FXML
private FooterController footerController;

@FXML private TextField firstNameField;
@FXML private TextField emailField;
@FXML private PasswordField passwordField;
@FXML private PasswordField confirmPasswordField;
@FXML private NavbarController navbarController;
@FXML private FooterController footerController;

@FXML private TextField firstNameField;
@FXML private TextField emailField;
@FXML private PasswordField passwordField;
@FXML private PasswordField confirmPasswordField;

@Override
protected void authTokenisSet() {
if (isLoggedin()){
LoaderScene.LoadScene("frontPage", new ActionEvent(), null, null, authToken);
}
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
@Override
protected void authTokenisSet() {
if (isLoggedin()) {
LoaderScene.LoadScene("frontPage", new ActionEvent(), null, null, authToken);
}
navbarController.setAuthToken(authToken);
footerController.setAuthToken(authToken);
}

@FXML
private void handleCreateAccount(ActionEvent event){
String nameText = firstNameField.getText();
String emailText = emailField.getText();
String password = passwordField.getText();
String confirmPassword = confirmPasswordField.getText();

if (nameText.isBlank() || emailText.isBlank() || password.isBlank() || confirmPassword.isBlank()) {
showAlert(Alert.AlertType.ERROR, "Empty input", "Please fill out all fields");
return;
}

if (emailText == null || emailText.isBlank() || !emailText.contains("@") || !emailText.contains(".")) {
showAlert(Alert.AlertType.ERROR, "Invalid Email", "Please enter a valid email");
return;
}
@FXML
private void handleCreateAccount(ActionEvent event) {
String nameText = firstNameField.getText();
String emailText = emailField.getText();
String password = passwordField.getText();
String confirmPassword = confirmPasswordField.getText();

if (!password.equals(confirmPassword)) {
showAlert(Alert.AlertType.ERROR, "Mismatch of password", "Password do not match");
return;
}
if (nameText.isBlank()
|| emailText.isBlank()
|| password.isBlank()
|| confirmPassword.isBlank()) {
showAlert(Alert.AlertType.ERROR, "Empty input", "Please fill out all fields");
return;
}

// login
boolean registerSuccess;
try {
registerSuccess = authToken.register(nameText,emailText, confirmPassword);
} catch (IllegalArgumentException e) {
showAlert(Alert.AlertType.ERROR, "Email already taken", "Email already taken by another user.");
return;
} catch (Exception e) {
e.printStackTrace();
showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred");
return;
if (emailText == null
|| emailText.isBlank()
|| !emailText.contains("@")
|| !emailText.contains(".")) {
showAlert(Alert.AlertType.ERROR, "Invalid Email", "Please enter a valid email");
return;
}

}
if (registerSuccess) {
showAlert(
Alert.AlertType.INFORMATION,
"Sign up sucsess",
"You have registered a new account! Please login with same credentials");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
if (!password.equals(confirmPassword)) {
showAlert(Alert.AlertType.ERROR, "Mismatch of password", "Password do not match");
return;
}

@FXML
private void switchToLoginPage(ActionEvent event){
System.out.println("Click!");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
// login
boolean registerSuccess;
try {
registerSuccess = authToken.register(nameText, emailText, confirmPassword);
} catch (IllegalArgumentException e) {
showAlert(
Alert.AlertType.ERROR, "Email already taken", "Email already taken by another user.");
return;
} catch (Exception e) {
e.printStackTrace();
showAlert(Alert.AlertType.ERROR, "Unexpected Error", "Unexpected error ocurred");
return;
}
if (registerSuccess) {
showAlert(
Alert.AlertType.INFORMATION,
"Sign up sucsess",
"You have registered a new account! Please login with same credentials");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
}

@FXML
private void switchToLoginPage(ActionEvent event) {
System.out.println("Click!");
LoaderScene.LoadScene("loginSite", event, null, null, authToken);
}
}
Loading