diff --git a/helpmehelpapplication/pom.xml b/helpmehelpapplication/pom.xml
index 2fdce09..7b2f137 100644
--- a/helpmehelpapplication/pom.xml
+++ b/helpmehelpapplication/pom.xml
@@ -62,6 +62,13 @@
2.4.240
test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 5.23.0
+ test
+
diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/DAO/DonationDAOTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/DAO/DonationDAOTest.java
index 988f97e..00970bb 100644
--- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/DAO/DonationDAOTest.java
+++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/DAO/DonationDAOTest.java
@@ -8,6 +8,7 @@
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.DatabaseSetup;
import ntnu.systemutvikling.team6.models.Charity;
+import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -23,7 +24,8 @@ void setUp() {
charity = new Charity("123456", "https://test.org", "Test Charity", true, "approved");
- manager.addAPIDataToTable(java.util.List.of(charity));
+ APIToDatabaseService service = new APIToDatabaseService(conn);
+ service.addAPIDataToTable(java.util.List.of(charity));
}
@Test
diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DatabaseManagerTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DatabaseManagerTest.java
index 689048a..2ef32eb 100644
--- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DatabaseManagerTest.java
+++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/database/DatabaseManagerTest.java
@@ -5,19 +5,27 @@
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
-
+import ntnu.systemutvikling.team6.database.Readers.CharitySelect;
+import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.CharityRegistry;
+import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import org.junit.jupiter.api.*;
class DatabaseManagerTest {
private DatabaseSetup dbManager;
+ private APIToDatabaseService service;
+ private CharitySelect charitySelect;
+ private DonationSelect donationSelect;
@BeforeEach
public void setUp() throws SQLException {
DatabaseConnection conn = new DatabaseConnection();
this.dbManager = new DatabaseSetup(conn);
+ this.service = new APIToDatabaseService(conn);
+ this.charitySelect = new CharitySelect(conn);
+ this.donationSelect = new DonationSelect(conn);
}
// Make sure you're connected to the NTNU network for this to work
@@ -48,14 +56,14 @@ void updateCharitiesShouldInsertCorrectData() throws SQLException {
boolean is_pre_approved = false;
Charity charity = new Charity(org_number, url, name, is_pre_approved, status);
- dbManager.addAPIDataToTable(List.of(charity));
+ service.addAPIDataToTable(List.of(charity));
Charity charity2 = new Charity(org_number, url, name + " Updated", is_pre_approved, status);
- dbManager.addAPIDataToTable(List.of(charity2));
+ service.addAPIDataToTable(List.of(charity2));
dbManager.createTables();
- CharityRegistry registry = dbManager.getCharitiesFromDB();
+ CharityRegistry registry = charitySelect.getCharitiesFromDB();
Charity insertedCharity = registry.findCharityByOrgnumber("12345").get();
assertEquals("Test Charity Updated", insertedCharity.getName());
}
@@ -91,13 +99,13 @@ void updateCharitiesShouldRemoveDataNotInList() throws SQLException {
charityListBefore.add(charity2);
charityListBefore.add(charity3);
- dbManager.addAPIDataToTable(charityListBefore);
+ service.addAPIDataToTable(charityListBefore);
List charityListNew = new ArrayList<>();
charityListNew.add(charity1);
charityListNew.add(charity3);
- dbManager.addAPIDataToTable(charityListNew);
+ service.addAPIDataToTable(charityListNew);
try (Connection conn = new DatabaseConnection().getMySqlConnection()) {
PreparedStatement stmt =
@@ -117,7 +125,7 @@ void updateCharitiesShouldRemoveDataNotInList() throws SQLException {
void tempTableShouldNotExistAfterUpdating() throws SQLException {
Charity charity = new Charity("99999", "https://temp.no", "Temp Charity", false, "approved");
- dbManager.addAPIDataToTable(List.of(charity));
+ service.addAPIDataToTable(List.of(charity));
try (Connection conn = new DatabaseConnection().getMySqlConnection()) {
PreparedStatement stmt = conn.prepareStatement("SELECT * FROM temp_api_charities");
diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java
index 222e29b..29fd72e 100644
--- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java
+++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.java
@@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDateTime;
+import java.time.chrono.ChronoLocalDate;
import ntnu.systemutvikling.team6.models.user.Inbox;
import ntnu.systemutvikling.team6.models.user.Role;
import ntnu.systemutvikling.team6.models.user.Settings;
@@ -36,7 +37,9 @@ void testFeedbackInitialization() {
assertEquals(user, feedback.getUser());
// Date should be between before and after
- assertTrue(!feedback.getDate().isBefore(before) && !feedback.getDate().isAfter(after));
+ assertTrue(
+ !feedback.getDate().isBefore(ChronoLocalDate.from(before))
+ && !feedback.getDate().isAfter(ChronoLocalDate.from(after)));
}
@Test
diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/InboxTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/InboxTest.java
index 2dc7fa2..f3dc6ad 100644
--- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/InboxTest.java
+++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/InboxTest.java
@@ -16,8 +16,8 @@ public class InboxTest {
@BeforeEach
public void setup() {
inbox = new Inbox();
- newMessage = new Message("Title", "Someone", "Somewhere");
- newMessage2 = new Message("Title2", "Someone2", "Somewhere2");
+ newMessage = new Message("Title", UUID.randomUUID(), "Somewhere");
+ newMessage2 = new Message("Title2", UUID.randomUUID(), "Somewhere2");
}
@Test
diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java
index faae3ad..1faa986 100644
--- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java
+++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java
@@ -11,10 +11,10 @@ public class MessegeTest {
void shouldThrowExceptionIfNameIsNullOrEmpty() {
assertThrows(
IllegalArgumentException.class,
- () -> new Message(null, "Someone", "Something Somewhere Somehow"));
+ () -> new Message(null, UUID.randomUUID(), "Something Somewhere Somehow"));
assertThrows(
IllegalArgumentException.class,
- () -> new Message("", "Someone", "Something Somewhere Somehow"));
+ () -> new Message("", UUID.randomUUID(), "Something Somewhere Somehow"));
}
@Test
@@ -22,24 +22,23 @@ void shouldThrowExceptionIfFromIsNullOrEmpty() {
assertThrows(
IllegalArgumentException.class,
() -> new Message("Title", null, "Something Somewhere Somehow"));
- assertThrows(
- IllegalArgumentException.class,
- () -> new Message("Title", "", "Something Somewhere Somehow"));
}
@Test
void shouldThrowExceptionIfContentIsNullOrEmpty() {
- assertThrows(IllegalArgumentException.class, () -> new Message("Title", "Someone", null));
- assertThrows(IllegalArgumentException.class, () -> new Message("Title", "Someone", ""));
+ assertThrows(
+ IllegalArgumentException.class, () -> new Message("Title", UUID.randomUUID(), null));
+ assertThrows(IllegalArgumentException.class, () -> new Message("Title", UUID.randomUUID(), ""));
}
@Test
void GettersWork() {
- Message newMessage = new Message("Title", "Someone", "Somewhere");
+ UUID uuid = UUID.randomUUID();
+ Message newMessage = new Message("Title", uuid, "Somewhere");
assertInstanceOf(UUID.class, newMessage.getId());
assertEquals("Title", newMessage.getTitle());
- assertEquals("Someone", newMessage.getFrom());
+ assertEquals(uuid, newMessage.getFrom());
assertEquals("Somewhere", newMessage.getContent());
- assertEquals(LocalDate.now(), newMessage.getTimeAndDate().toLocalDate());
+ assertEquals(LocalDate.now(), newMessage.getTimeAndDate());
}
}