diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java index 966cf897..5e25df02 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/HmHApplication.java @@ -4,7 +4,6 @@ import java.net.http.HttpClient; import java.util.Objects; - import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java index ee3a19f1..e36472d0 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/AvailableOrganizationController.java @@ -26,7 +26,8 @@ * on the featured charity to see more details about it. The user can also switch to the charity * page or donation page for the selected charity. */ -public class AvailableOrganizationController extends BaseController implements NavbarFooterController { +public class AvailableOrganizationController extends BaseController + implements NavbarFooterController { @FXML private TextField searchField; @FXML private FlowPane cardsContainer; @@ -92,7 +93,8 @@ private void displayCharities(List 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(); @@ -119,7 +121,6 @@ public void setInitialSearch(String query) { searchField.setText(query); } - /** * This method is used to switch to the charity page for the selected charity. * diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java index 121ad3be..0635e7c5 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/CharityPageController.java @@ -41,7 +41,6 @@ public void setCharity(Charity charity) { CharityName.setText(charity.getName()); } - /** * This method is used to switch to the donation page. * diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java index 4a69ed54..0a500081 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/DonationPageController.java @@ -102,7 +102,7 @@ public void Donate(ActionEvent event) { if (result.isPresent() && result.get() == ButtonType.OK) { // Process donation - //processDonation(charity, user, amount); + // processDonation(charity, user, amount); showAlert( Alert.AlertType.INFORMATION, "Thank you!", diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java index b5b45226..752148f3 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/FrontpageController.java @@ -48,9 +48,7 @@ public class FrontpageController extends BaseController implements NavbarFooterC private List allCharities = new ArrayList<>(); @Override - protected void authTokenisSet(){ - - } + protected void authTokenisSet() {} /** * Initialize method for the front page. This method is called when the front page is loaded. It @@ -97,7 +95,6 @@ public void initialize() { } } - /** * This method is used to switch to the charity page for the selected charity * @@ -220,7 +217,8 @@ private void displayCharities(List 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(); cardController.setOrganization(charity); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java index da4af23a..a42a4665 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/BaseController.java @@ -3,15 +3,17 @@ import ntnu.systemutvikling.team6.service.AuthenticationService; public abstract class BaseController { - protected AuthenticationService authToken; + protected AuthenticationService authToken; - public void setAuthToken(AuthenticationService authToken){ - this.authToken = authToken; - authTokenisSet(); - }; - protected void authTokenisSet(){} // Do stuff after authtoken is set, on each controller + public void setAuthToken(AuthenticationService authToken) { + this.authToken = authToken; + authTokenisSet(); + } + ; - protected boolean isLoggedin(){ - return authToken.isLoggedin() && authToken != null; - } + protected void authTokenisSet() {} // Do stuff after authtoken is set, on each controller + + protected boolean isLoggedin() { + return authToken.isLoggedin() && authToken != null; + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarFooterController.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarFooterController.java index 0075893f..3f12e268 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarFooterController.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/controller/components/NavbarFooterController.java @@ -1,33 +1,31 @@ package ntnu.systemutvikling.team6.controller.components; import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.scene.control.TextField; public interface NavbarFooterController { - default void switchToFrontPage(ActionEvent event) { - System.out.println("Click!"); - LoaderScene.LoadScene("FrontPage", event, null, null); - } + default void switchToFrontPage(ActionEvent event) { + System.out.println("Click!"); + LoaderScene.LoadScene("FrontPage", event, null, null); + } - default void switchToAboutPage(ActionEvent event) { - System.out.println("Click!"); - LoaderScene.LoadScene("aboutPage", event, null, null); - } + default void switchToAboutPage(ActionEvent event) { + System.out.println("Click!"); + LoaderScene.LoadScene("aboutPage", event, null, null); + } - default void switchToProfilePage(ActionEvent event) { - System.out.println("Click!"); - LoaderScene.LoadScene("aboutPage", event, null, null); - } + default void switchToProfilePage(ActionEvent event) { + System.out.println("Click!"); + LoaderScene.LoadScene("aboutPage", event, null, null); + } - default void handleSearch(ActionEvent event) { - System.out.println("Click!"); - LoaderScene.LoadScene("aboutPage", event, null, null); - } + default void handleSearch(ActionEvent event) { + System.out.println("Click!"); + LoaderScene.LoadScene("aboutPage", event, null, null); + } - default void switchToLoginPage(ActionEvent event) { - System.out.println("Click!"); - LoaderScene.LoadScene("aboutPage", event, null, null); - } + default void switchToLoginPage(ActionEvent event) { + System.out.println("Click!"); + LoaderScene.LoadScene("aboutPage", event, null, null); + } } diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/DonationDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/DonationDAO.java index 730accac..1726870a 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/DonationDAO.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/DonationDAO.java @@ -13,11 +13,11 @@ public class DonationDAO { private final DatabaseConnection connection; - public DonationDAO(DatabaseConnection connection) { - this.connection = connection; - } + public DonationDAO(DatabaseConnection connection) { + this.connection = connection; + } - /** + /** * Gets the total ammount of donations for a given charity, and sends it to the database throught * MySQL. * @@ -40,7 +40,6 @@ INSERT INTO Donations (UUID_Donations, amount, date, charity_id, user_id) ps.setString(4, charity.getUUID().toString()); ps.setString(5, user.getId().toString()); - ps.executeUpdate(); conn.commit(); } catch (SQLException e) { diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/UserDAO.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/UserDAO.java index 2125a088..7929da7f 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/UserDAO.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DAO/UserDAO.java @@ -16,14 +16,13 @@ public class UserDAO { private final DatabaseConnection connection; - public UserDAO(DatabaseConnection connection) { - this.connection = connection; - } + public UserDAO(DatabaseConnection connection) { + this.connection = connection; + } - /** + /** * Gets the user and settings information and sends it to the database through MySQL. * - * * @param user the user to be saved in the database. * @throws RuntimeException if a database error occurs during the operation * @return true or false based on if the register is a success or not @@ -80,7 +79,6 @@ INSERT INTO Settings ( psSettings.setBoolean(4, user.getSettings().isLightMode()); psSettingsRows = psSettings.executeUpdate(); - } conn.commit(); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/CharitySelect.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/CharitySelect.java index c59db00c..5beaf2e6 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/CharitySelect.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/CharitySelect.java @@ -115,7 +115,7 @@ public CharityRegistry getCharitiesFromDB() { rs.getString("user_email"), rs.getString("user_password"), rs.getString("role")); - userWithMinimalSettingsAndInbox.setSettings(new Settings(false, Language.ENGLISH, false)); + userWithMinimalSettingsAndInbox.setSettings(new Settings(false, Language.ENGLISH, false)); Feedback feedback = new Feedback( @@ -181,7 +181,7 @@ public ArrayList getFeedbackforCharityUUID(String charity_uuid) { Feedback feedback = new Feedback( rs.getString("UUID_feedback"), - userWithSettingsAndNoInbox, + userWithSettingsAndNoInbox, rs.getString("feedback_comment"), LocalDate.parse(rs.getString("feedback_date"))); Feedbacks.add(feedback); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java index 4f467457..6956dc5d 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/Readers/UserSelect.java @@ -30,12 +30,12 @@ public UserSelect(DatabaseConnection connection) { this.connection = connection; } - public boolean isUsernameTaken(String username){ + public boolean isUsernameTaken(String username) { try (Connection conn = connection.getMySqlConnection(); - Statement stmt = conn.createStatement()) { + Statement stmt = conn.createStatement()) { String mysql = - """ + """ SELECT UUID_User FROM User WHERE user_name = ? """; PreparedStatement statement = conn.prepareStatement(mysql); @@ -53,7 +53,6 @@ public boolean isUsernameTaken(String username){ return false; } - /** * Retrieves a single {@link User} from the database matching the given username and password. * diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java index 3f4a8cdf..8bf310fe 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java @@ -209,8 +209,7 @@ public void setFeedbacks(ArrayList feedbacks) { this.feedbacks = feedbacks; } - public void setUUIDFromString(String uuid){ + public void setUUIDFromString(String uuid) { this.UUID = java.util.UUID.fromString(uuid); } } - diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/User.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/User.java index 04fc6969..b32b208b 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/User.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/user/User.java @@ -38,8 +38,14 @@ public class User { * @throws IllegalArgumentException if any required argument is invalid. */ public User( - String displayName, String username, String email, String password, Role role, Settings settings, Inbox inbox) { - if (displayName == null || username.isBlank()){ + String displayName, + String username, + String email, + String password, + Role role, + Settings settings, + Inbox inbox) { + if (displayName == null || username.isBlank()) { throw new IllegalArgumentException("displayName cannot be null or blank."); } @@ -86,7 +92,13 @@ public User( * @param role users role * @throws IllegalArgumentException if any required argument is invalid. */ - public User(String uuid, String displayName, String username, String email, String password, String role) { + public User( + String uuid, + String displayName, + String username, + String email, + String password, + String role) { if (uuid == null || uuid.isBlank()) { throw new IllegalArgumentException("UUID cannot be null or blank."); diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/APIToDatabaseService.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/APIToDatabaseService.java index 7c2a7fab..9c50ad91 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/APIToDatabaseService.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/APIToDatabaseService.java @@ -2,7 +2,6 @@ import java.sql.Connection; import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; import java.util.List; import java.util.UUID; @@ -41,7 +40,8 @@ public void addAPIDataToTable(List charities) { try { conn = connection.getMySqlConnection(); conn.setAutoCommit(false); - String sql1 = """ + String sql1 = + """ INSERT INTO Charities (UUID_charities, org_number, pre_approved, status) VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE @@ -49,7 +49,8 @@ INSERT INTO Charities (UUID_charities, org_number, pre_approved, status) status = VALUES(status); """; - String sql2 = """ + String sql2 = + """ INSERT INTO CharityVanity (UUID_charity, charity_name, charity_link, description, logoURL, key_values, logoBlob) VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE @@ -62,7 +63,7 @@ INSERT INTO CharityVanity (UUID_charity, charity_name, charity_link, description """; try (PreparedStatement ps1 = conn.prepareStatement(sql1); - PreparedStatement ps2 = conn.prepareStatement(sql2)) { + PreparedStatement ps2 = conn.prepareStatement(sql2)) { for (Charity charity : charities) { String uuid; @@ -88,7 +89,6 @@ INSERT INTO CharityVanity (UUID_charity, charity_name, charity_link, description ps2.setString(6, charity.getKeyValues()); ps2.setBytes(7, charity.getLogoBlob()); ps2.executeUpdate(); - } } catch (Exception e) { diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java index ee780582..b2ee203a 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/service/AuthenticationService.java @@ -7,111 +7,106 @@ import ntnu.systemutvikling.team6.models.user.Settings; import ntnu.systemutvikling.team6.models.user.User; - /** - * Service class responsible for handling user authentication operations, - * including login, registration, and logout functionality. - *

- * Maintains the state of the currently authenticated user throughout the session. - *

+ * Service class responsible for handling user authentication operations, including login, + * registration, and logout functionality. + * + *

Maintains the state of the currently authenticated user throughout the session. */ public class AuthenticationService { - /** Handles read operations for user data from the database. */ - private final UserSelect userDataReader; - /** Handles write operations for user data to the database. */ - private final UserDAO userDataSender; - - /** The currently authenticated user, or {@code null} if no user is logged in. */ - private User currentUser; - - /** - * Constructs an {@code AuthenticationService} with the specified data access objects. - * - * @param userDataReader the data reader used to query user information from the database - * @param userDataSender the DAO used to persist new user registrations to the database - */ - public AuthenticationService(UserSelect userDataReader, UserDAO userDataSender) { - this.userDataReader = userDataReader; - this.userDataSender = userDataSender; - } - - /** - * Attempts to authenticate a user with the given credentials. - *

- * If a matching user is found in the database, they are set as the current user - * and the method returns {@code true}. - *

- * - * @param username the username of the user attempting to log in - * @param password the password of the user attempting to log in - * @return {@code true} if authentication was successful; {@code false} otherwise - */ - public boolean login(String username, String password){ - User user = userDataReader.getUserFromDBUsernameAndPassword(username, password); - - if (user != null){ - currentUser = user; - return true; - } - - return false; + /** Handles read operations for user data from the database. */ + private final UserSelect userDataReader; + + /** Handles write operations for user data to the database. */ + private final UserDAO userDataSender; + + /** The currently authenticated user, or {@code null} if no user is logged in. */ + private User currentUser; + + /** + * Constructs an {@code AuthenticationService} with the specified data access objects. + * + * @param userDataReader the data reader used to query user information from the database + * @param userDataSender the DAO used to persist new user registrations to the database + */ + public AuthenticationService(UserSelect userDataReader, UserDAO userDataSender) { + this.userDataReader = userDataReader; + this.userDataSender = userDataSender; + } + + /** + * Attempts to authenticate a user with the given credentials. + * + *

If a matching user is found in the database, they are set as the current user and the method + * returns {@code true}. + * + * @param username the username of the user attempting to log in + * @param password the password of the user attempting to log in + * @return {@code true} if authentication was successful; {@code false} otherwise + */ + public boolean login(String username, String password) { + User user = userDataReader.getUserFromDBUsernameAndPassword(username, password); + + if (user != null) { + currentUser = user; + return true; } - /** - * Registers a new user account with the provided details. - *

- * The new user is assigned the {@link Role#NORMAL_USER} role and default - * {@link Settings} and {@link Inbox}. Registration will fail if the - * username is already taken or if the database operation is unsuccessful. - * On success, the new user is set as the current user. - *

- * - * @param displayName the display name shown on the user's profile - * @param username the unique username for the new account - * @param email the email address associated with the new account - * @param password the password for the new account - * @return {@code true} if registration was successful; {@code false} if the - * username is already taken or the database operation failed - */ - public boolean register(String displayName, String username, String email, String password ){ - User newUser = new User(displayName, username, email, password, Role.NORMAL_USER, new Settings(), new Inbox()); - - if(userDataReader.isUsernameTaken(username)){ - return false; - } - - boolean success = userDataSender.registerUser(newUser); - - if (success){ - currentUser = newUser; - return true; - } - return false; + return false; + } + + /** + * Registers a new user account with the provided details. + * + *

The new user is assigned the {@link Role#NORMAL_USER} role and default {@link Settings} and + * {@link Inbox}. Registration will fail if the username is already taken or if the database + * operation is unsuccessful. On success, the new user is set as the current user. + * + * @param displayName the display name shown on the user's profile + * @param username the unique username for the new account + * @param email the email address associated with the new account + * @param password the password for the new account + * @return {@code true} if registration was successful; {@code false} if the username is already + * taken or the database operation failed + */ + public boolean register(String displayName, String username, String email, String password) { + User newUser = + new User( + displayName, username, email, password, Role.NORMAL_USER, new Settings(), new Inbox()); + + if (userDataReader.isUsernameTaken(username)) { + return false; } - /** - * Logs out the currently authenticated user by clearing the current user state. - */ - public void logout (){ - currentUser = null; - } - - - /** - * Returns the currently authenticated user. - * - * @return the current {@link User}, or {@code null} if no user is logged in - */ - public User getCurrentUser(){ - return currentUser; - } + boolean success = userDataSender.registerUser(newUser); - /** - * Checks whether a user is currently logged in. - * - * @return {@code true} if a user is authenticated; {@code false} otherwise - */ - public boolean isLoggedin(){ - return currentUser != null; + if (success) { + currentUser = newUser; + return true; } + return false; + } + + /** Logs out the currently authenticated user by clearing the current user state. */ + public void logout() { + currentUser = null; + } + + /** + * Returns the currently authenticated user. + * + * @return the current {@link User}, or {@code null} if no user is logged in + */ + public User getCurrentUser() { + return currentUser; + } + + /** + * Checks whether a user is currently logged in. + * + * @return {@code true} if a user is authenticated; {@code false} otherwise + */ + public boolean isLoggedin() { + return currentUser != null; + } } diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_org_Settings.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_org_Settings.fxml index 51c8651c..b18e6308 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_org_Settings.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_org_Settings.fxml @@ -20,7 +20,7 @@ - + diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml index 030f54fc..ff79ad56 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_user_history.fxml @@ -20,7 +20,7 @@ - + diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_user_inbox.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_user_inbox.fxml index 0e5e0d5d..73a1a4e6 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_user_inbox.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_user_inbox.fxml @@ -20,7 +20,7 @@ - + diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml index 45aeb1a9..c6f621c3 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_user_interests.fxml @@ -21,7 +21,7 @@ - + diff --git a/helpmehelpapplication/src/main/resources/fxml/profile_user_settings.fxml b/helpmehelpapplication/src/main/resources/fxml/profile_user_settings.fxml index cd6d9973..2984ff7e 100644 --- a/helpmehelpapplication/src/main/resources/fxml/profile_user_settings.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/profile_user_settings.fxml @@ -20,7 +20,7 @@ - + diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DAO/DonationDAOTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DAO/DonationDAOTest.java index 5d80c03a..110ecfd4 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DAO/DonationDAOTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DAO/DonationDAOTest.java @@ -6,7 +6,6 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.util.UUID; - import ntnu.systemutvikling.team6.database.DatabaseConnection; import ntnu.systemutvikling.team6.database.DatabaseSetup; import ntnu.systemutvikling.team6.models.Charity; @@ -41,7 +40,10 @@ void setUp() { void addDonationShouldInsertDonationIntoDatabase() throws Exception { double amount = 100.0; - DonationDAO.addDonation(charity, new User(UUID.randomUUID().toString(), "ad", "dwad@ca.com", "CHARITY_USER", "NORMAL_USER"), amount); + DonationDAO.addDonation( + charity, + new User(UUID.randomUUID().toString(), "ad", "dwad@ca.com", "CHARITY_USER", "NORMAL_USER"), + amount); try (Connection conn = new DatabaseConnection().getMySqlConnection()) { PreparedStatement stmt = diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/CharitySelectTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/CharitySelectTest.java index 426bf251..97cdd5ff 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/CharitySelectTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/CharitySelectTest.java @@ -7,7 +7,6 @@ import java.sql.*; import java.util.ArrayList; import java.util.UUID; - import ntnu.systemutvikling.team6.database.DatabaseConnection; import ntnu.systemutvikling.team6.models.Charity; import ntnu.systemutvikling.team6.models.Feedback; diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/DonationSelectTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/DonationSelectTest.java index 92b4a7ca..58792312 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/DonationSelectTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/DonationSelectTest.java @@ -7,7 +7,6 @@ import java.sql.*; import java.time.LocalDate; import java.util.UUID; - import ntnu.systemutvikling.team6.database.DatabaseConnection; import ntnu.systemutvikling.team6.models.Donation; import ntnu.systemutvikling.team6.models.registry.DonationRegistry; @@ -69,10 +68,10 @@ void getDonationFromDB_singleRow_returnsSingleDonation() throws Exception { when(mockResultSet.next()).thenReturn(true, false); String charityId = UUID.randomUUID().toString(); stubCharityColumns( - charityId, "123456789", "Test Charity", "https://example.org", true, "ACTIVE"); + charityId, "123456789", "Test Charity", "https://example.org", true, "ACTIVE"); String userId = UUID.randomUUID().toString(); String donationId = UUID.randomUUID().toString(); - stubDonationColumns(donationId, 250.0, LocalDate.of(2024, 5, 20),userId); + stubDonationColumns(donationId, 250.0, LocalDate.of(2024, 5, 20), userId); DonationRegistry registry = donationSelect.getDonationFromDB(); @@ -94,7 +93,7 @@ void getDonationFromDB_singleRow_charityMappedCorrectly() throws Exception { String charityId = UUID.randomUUID().toString(); String donationId = UUID.randomUUID().toString(); stubCharityColumns( - charityId, "987654321", "Help Fund", "https://helpfund.org", false, "PENDING"); + charityId, "987654321", "Help Fund", "https://helpfund.org", false, "PENDING"); String userId = UUID.randomUUID().toString(); stubDonationColumns(donationId, 100.0, LocalDate.of(2024, 1, 1), userId); @@ -124,8 +123,7 @@ void getDonationFromDB_twoRows_returnsTwoDonations() throws Exception { when(mockResultSet.getString("status")).thenReturn("ACTIVE", "INACTIVE"); String donationId = UUID.randomUUID().toString(); String donationId2 = UUID.randomUUID().toString(); - when(mockResultSet.getString("UUID_Donations")) - .thenReturn(donationId, donationId2); + when(mockResultSet.getString("UUID_Donations")).thenReturn(donationId, donationId2); when(mockResultSet.getDouble("amount")).thenReturn(500.0, 750.0); Date sqlDate = Date.valueOf(LocalDate.of(2024, 8, 10)); @@ -156,7 +154,7 @@ void getDonationFromDB_zeroAmount_storedCorrectly() throws Exception { String charityId = UUID.randomUUID().toString(); when(mockResultSet.next()).thenReturn(true, false); stubCharityColumns( - charityId, "123456789", "Test Charity", "https://example.org", true, "ACTIVE"); + charityId, "123456789", "Test Charity", "https://example.org", true, "ACTIVE"); String userId = UUID.randomUUID().toString(); String donationId = UUID.randomUUID().toString(); @@ -178,7 +176,7 @@ void getDonationFromDB_largeAmount_storedCorrectly() throws Exception { String charityId = UUID.randomUUID().toString(); String donationId = UUID.randomUUID().toString(); stubCharityColumns( - charityId, "123456789", "Test Charity", "https://example.org", true, "ACTIVE"); + charityId, "123456789", "Test Charity", "https://example.org", true, "ACTIVE"); String userId = UUID.randomUUID().toString(); stubDonationColumns(donationId, 1_000_000.99, LocalDate.of(2024, 12, 31), userId); @@ -226,7 +224,8 @@ private void stubCharityColumns( } /** Stubs all donation-related columns on the mock ResultSet. */ - private void stubDonationColumns(String uuid, double amount, LocalDate date, String userId) throws SQLException { + private void stubDonationColumns(String uuid, double amount, LocalDate date, String userId) + throws SQLException { when(mockResultSet.getString("UUID_Donations")).thenReturn(uuid); when(mockResultSet.getDouble("amount")).thenReturn(amount); when(mockResultSet.getBoolean("isAnonymous")).thenReturn(false); diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/UserSelectTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/UserSelectTest.java index ad99e9e2..e408e02f 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/UserSelectTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/Readers/UserSelectTest.java @@ -272,7 +272,7 @@ void getSettingsForUser_matchingRow_returnsSettings() throws Exception { Settings result = userSelect.getSettingsForUser(USER_UUID); assertNotNull(result); - //assertTrue(result.isAnonymous()); + // assertTrue(result.isAnonymous()); assertEquals(Language.ENGLISH, result.getLanguage()); assertFalse(result.isLightMode()); } @@ -350,7 +350,6 @@ void getInboxForUser_twoRows_inboxContainsTwoMessages() throws Exception { when(mockResultSet.getString("message_date")).thenReturn("2024-06-15"); when(mockResultSet.getString("message_content")).thenReturn("Hello!"); - Inbox result = userSelect.getInboxForUser(USER_UUID); assertEquals(2, result.getMessages().size()); diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java index 1c6fbf08..bf16982f 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java @@ -4,7 +4,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; - import ntnu.systemutvikling.team6.models.user.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java index 973aca3f..5b291339 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/scraper/scraperComponents/URLCharityScraperTest.java @@ -5,8 +5,6 @@ import java.util.ArrayList; import java.util.List; - -import ntnu.systemutvikling.team6.scraper.scraperComponents.URLCharityScraper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; @@ -40,15 +38,12 @@ void updateDescriptionShouldReturnCorrectDescriptionWithoutReadMore() { WebElement p1 = mock(WebElement.class); WebElement p2 = mock(WebElement.class); - when(p1.getText()).thenReturn("Short description"); when(p2.getText()).thenReturn(""); - when(scraper.findElements(By.cssSelector("a.read-more"))) - .thenReturn(List.of()); + when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of()); - when(scraper.findElements(By.cssSelector(".information"))) - .thenReturn(List.of(p1, p2)); + when(scraper.findElements(By.cssSelector(".information"))).thenReturn(List.of(p1, p2)); scraper.updateDescription(); @@ -59,29 +54,29 @@ void updateDescriptionShouldReturnCorrectDescriptionWithoutReadMore() { assertFalse(result.isBlank(), "Blank paragraph should not be included."); } - @Test - void updateDescriptionShouldReturnCorrectDescriptionWithReadMore() { - WebElement p1 = mock(WebElement.class); - WebElement extra = mock(WebElement.class); - WebElement readMore = mock(WebElement.class); + @Test + void updateDescriptionShouldReturnCorrectDescriptionWithReadMore() { + WebElement p1 = mock(WebElement.class); + WebElement extra = mock(WebElement.class); + WebElement readMore = mock(WebElement.class); - when(p1.getText()).thenReturn("Intro"); - when(extra.getText()).thenReturn("Extra info"); + when(p1.getText()).thenReturn("Intro"); + when(extra.getText()).thenReturn("Extra info"); - when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of(readMore)); + when(scraper.findElements(By.cssSelector("a.read-more"))).thenReturn(List.of(readMore)); - when(scraper.findElement(By.cssSelector("a.read-more"))).thenReturn(readMore); + when(scraper.findElement(By.cssSelector("a.read-more"))).thenReturn(readMore); - when(scraper.findElements(By.cssSelector(".information"))).thenReturn(List.of(p1, extra)); + when(scraper.findElements(By.cssSelector(".information"))).thenReturn(List.of(p1, extra)); - scraper.updateDescription(); + scraper.updateDescription(); - String result = scraper.getDescription(); + String result = scraper.getDescription(); - verify(readMore).click(); - assertTrue(result.contains("Intro")); - assertTrue(result.contains("Extra info")); - } + verify(readMore).click(); + assertTrue(result.contains("Intro")); + assertTrue(result.contains("Extra info")); + } @Test void updateLogoShouldReturnCorrectLogoURL() { @@ -104,9 +99,9 @@ void updateCategoriesShouldReturnCorrectCategories() { when(c1.getText()).thenReturn("Health"); when(c2.getText()).thenReturn("Education"); - List categories = new ArrayList<>(); - categories.add("Health"); - categories.add("Education"); + List categories = new ArrayList<>(); + categories.add("Health"); + categories.add("Education"); when(scraper.findElements(By.cssSelector(".tag-label"))).thenReturn(List.of(c1, c2)); @@ -163,42 +158,51 @@ void scrapeCharityPageShouldCallAllRelevantMethods() { verify(spyScraper).updateKeyValues(); } - @Test - void updateLogoShouldHandleException() { - when(scraper.findElement(By.cssSelector(".logo > img"))).thenThrow(new RuntimeException("Not found")); + @Test + void updateLogoShouldHandleException() { + when(scraper.findElement(By.cssSelector(".logo > img"))) + .thenThrow(new RuntimeException("Not found")); - scraper.updateLogo(); + scraper.updateLogo(); - assertNull(scraper.getLogoURL(), "Program should handle the exception and the logo should be null."); - } + assertNull( + scraper.getLogoURL(), "Program should handle the exception and the logo should be null."); + } - @Test - void updateCategoriesShouldHandleException() { - when(scraper.findElements(By.cssSelector(".tag-label"))).thenThrow(new RuntimeException("Fail")); + @Test + void updateCategoriesShouldHandleException() { + when(scraper.findElements(By.cssSelector(".tag-label"))) + .thenThrow(new RuntimeException("Fail")); - scraper.updateCategories(); + scraper.updateCategories(); - assertEquals(new ArrayList<>(), scraper.getCategories(), "Program should handle the exception " + - "and the categories should be null."); - } + assertEquals( + new ArrayList<>(), + scraper.getCategories(), + "Program should handle the exception " + "and the categories should be null."); + } - @Test - void updateKeyValuesShouldHandleException() { - when(scraper.findElement(any(By.class))).thenThrow(new RuntimeException("Fail")); + @Test + void updateKeyValuesShouldHandleException() { + when(scraper.findElement(any(By.class))).thenThrow(new RuntimeException("Fail")); - scraper.updateKeyValues(); + scraper.updateKeyValues(); - assertEquals("", scraper.getKeyValues(), "Program should handle the exception and the " + - "exception and the key values should be empty."); - } + assertEquals( + "", + scraper.getKeyValues(), + "Program should handle the exception and the " + + "exception and the key values should be empty."); + } - @Test - void updateDescriptionShouldHandleException() { - when(scraper.findElements(any(By.class))).thenThrow(new RuntimeException("Fail")); + @Test + void updateDescriptionShouldHandleException() { + when(scraper.findElements(any(By.class))).thenThrow(new RuntimeException("Fail")); - scraper.updateDescription(); + scraper.updateDescription(); - assertNull(scraper.getDescription(), "Program should handle the exception and the " + - "description should be null."); - } + assertNull( + scraper.getDescription(), + "Program should handle the exception and the " + "description should be null."); + } }