Skip to content

Commit

Permalink
Feat: Concurrent test pass, to not get compiling errors
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Apr 24, 2026
1 parent 4151fee commit b4448de
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.DAO.CategoryDAO;
import ntnu.systemutvikling.team6.database.DAO.CharityDAO;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.registry.CharityRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import ntnu.systemutvikling.team6.controller.components.*;
import ntnu.systemutvikling.team6.database.DAO.DonationDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.registry.DonationRegistry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import ntnu.systemutvikling.team6.controller.components.*;
import ntnu.systemutvikling.team6.database.DAO.DonationDAO;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.registry.DonationRegistry;
import ntnu.systemutvikling.team6.models.user.Inbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ AND NOT EXISTS (
SELECT 1 FROM CharityVanity cv WHERE cv.UUID_charity = c.UUID_charities
)
AND NOT EXISTS (
SELECT 1 FROM CharityUsers cu WHERE cu.Charities_UUID_charities = c.UUID_charities
SELECT 1 FROM CharityUsers cu WHERE cu.TheCharity = c.UUID_charities
);
""";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.time.LocalDate;
import java.util.UUID;
import ntnu.systemutvikling.team6.database.DatabaseConnection;
import ntnu.systemutvikling.team6.database.DatabaseSetup;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.models.Donation;
import ntnu.systemutvikling.team6.models.user.Inbox;
import ntnu.systemutvikling.team6.models.user.Role;
import ntnu.systemutvikling.team6.models.user.Settings;
import ntnu.systemutvikling.team6.models.user.User;
import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -42,16 +47,20 @@ void addDonationShouldInsertDonationIntoDatabase() throws Exception {

DonationDAO donationDAO = new DonationDAO(new DatabaseConnection());

donationDAO.addDonation(
charity,
new User(

User user = new User(
UUID.randomUUID().toString(),
"ad",
"aduser",
"dwad@ca.com",
"secret",
"NORMAL_USER"),
amount);
Role.NORMAL_USER,
new Settings(),
new Inbox());
donationDAO.addDonation(new Donation(
amount,
LocalDate.now(),
charity,
user
));

try (Connection conn = new DatabaseConnection().getMySqlConnection()) {
PreparedStatement stmt =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.sql.*;
import java.util.List;
import ntnu.systemutvikling.team6.database.DAO.CharityDAO;
import ntnu.systemutvikling.team6.database.Readers.DonationSelect;
import ntnu.systemutvikling.team6.database.DAO.DonationDAO;
import ntnu.systemutvikling.team6.models.Charity;
import ntnu.systemutvikling.team6.service.APIToDatabaseService;
import org.junit.jupiter.api.*;
Expand All @@ -15,15 +15,15 @@ class DatabaseSetupTest {
private DatabaseSetup dbManager;
private APIToDatabaseService service;
private CharityDAO charitySelect;
private DonationSelect donationSelect;
private DonationDAO donationDAO;

@BeforeEach
public void setUp() throws SQLException {
DatabaseConnection conn = new DatabaseConnection();
this.dbManager = new DatabaseSetup(conn);
this.service = new APIToDatabaseService(conn);
this.charitySelect = new CharityDAO(conn);
this.donationSelect = new DonationSelect(conn);
this.donationDAO = new DonationDAO(conn);
}

// Make sure you're connected to the NTNU network for this to work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public void setup() {

user =
new User(
"Name",
"username",
"Valid@gmail.com",
"123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public void setup() {
settings = new Settings(); // default anonymous = true
user =
new User(
"Name",
"username",
"Valid@gmail.com",
"123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import ntnu.systemutvikling.team6.models.Charity;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

Expand All @@ -15,9 +17,12 @@ public class InboxTest {

@BeforeEach
public void setup() {
Charity charity = new Charity("1234", "link.com", "name", false, "approved");
inbox = new Inbox();
newMessage = new Message("Title", UUID.randomUUID(), "Somewhere");
newMessage2 = new Message("Title2", UUID.randomUUID(), "Somewhere2");
newMessage = new Message("Title", charity, "Somewhere");

Charity charity2 = new Charity("5678", "link2.com", "name2", false, "approved");
newMessage2 = new Message("Title2",charity2 , "Somewhere2");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

import java.time.LocalDate;
import java.util.UUID;

import ntnu.systemutvikling.team6.models.Charity;
import org.junit.jupiter.api.Test;

public class MessegeTest {
@Test
void shouldThrowExceptionIfNameIsNullOrEmpty() {
Charity charity = new Charity("1234", "link.com", "name", false, "approved");
assertThrows(
IllegalArgumentException.class,
() -> new Message(null, UUID.randomUUID(), "Something Somewhere Somehow"));
() -> new Message(null, charity, "Something Somewhere Somehow"));
assertThrows(
IllegalArgumentException.class,
() -> new Message("", UUID.randomUUID(), "Something Somewhere Somehow"));
() -> new Message("", charity, "Something Somewhere Somehow"));
}

@Test
Expand All @@ -26,15 +29,18 @@ void shouldThrowExceptionIfFromIsNullOrEmpty() {

@Test
void shouldThrowExceptionIfContentIsNullOrEmpty() {
Charity charity = new Charity("1234", "link.com", "name", false, "approved");

assertThrows(
IllegalArgumentException.class, () -> new Message("Title", UUID.randomUUID(), null));
assertThrows(IllegalArgumentException.class, () -> new Message("Title", UUID.randomUUID(), ""));
IllegalArgumentException.class, () -> new Message("Title", charity, null));
assertThrows(IllegalArgumentException.class, () -> new Message("Title", charity, ""));
}

@Test
void GettersWork() {
Charity charity = new Charity("1234", "link.com", "name", false, "approved");
UUID uuid = UUID.randomUUID();
Message newMessage = new Message("Title", uuid, "Somewhere");
Message newMessage = new Message("Title", charity, "Somewhere");
assertInstanceOf(UUID.class, newMessage.getId());
assertEquals("Title", newMessage.getTitle());
assertEquals(uuid, newMessage.getFrom());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class UserTest {

@Nested
class constructorTests {
private final String validDisplayName = "Name";
private final String validUsername = "username";
private final String validEmail = "Email@gmail.com";
private final String validPassword = "Password";
Expand All @@ -24,7 +23,6 @@ void shouldThrowIfDisplayNameIsNull() {
() ->
new User(
null,
validUsername,
validEmail,
validPassword,
validRole,
Expand All @@ -39,7 +37,6 @@ void shouldThrowIfDisplayNameIsBlank() {
() ->
new User(
" ",
validUsername,
validEmail,
validPassword,
validRole,
Expand All @@ -53,7 +50,6 @@ void shouldThrowIfUsernameIsNull() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
null,
validEmail,
validPassword,
Expand All @@ -68,7 +64,6 @@ void shouldThrowIfUsernameIsBlank() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
" ",
validEmail,
validPassword,
Expand All @@ -86,7 +81,6 @@ void shouldThrowIfEmailIsNull() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
null,
validPassword,
Expand All @@ -101,7 +95,6 @@ void shouldThrowIfEmailIsBlank() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
" ",
validPassword,
Expand All @@ -116,7 +109,6 @@ void shouldThrowIfEmailDoesNotContainAt() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
"test.gmail.com",
validPassword,
Expand All @@ -131,7 +123,6 @@ void shouldThrowIfEmailDoesNotContainPeriod() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
"test@gmailcom",
validPassword,
Expand All @@ -147,7 +138,6 @@ void shouldThrowIfPasswordIsNull() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
validEmail,
null,
Expand All @@ -162,7 +152,6 @@ void shouldThrowIfRoleIsNull() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
validEmail,
validPassword,
Expand All @@ -177,7 +166,6 @@ void shouldThrowIfPasswordIsBlank() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
validEmail,
" ",
Expand All @@ -192,7 +180,6 @@ void shouldThrowIfSettingsIsNull() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
validEmail,
validPassword,
Expand All @@ -207,7 +194,6 @@ void shouldThrowIfInboxIsNull() {
IllegalArgumentException.class,
() ->
new User(
validDisplayName,
validUsername,
validEmail,
validPassword,
Expand All @@ -220,7 +206,6 @@ void shouldThrowIfInboxIsNull() {
void shouldCreateUser() {
User user =
new User(
validDisplayName,
validUsername,
validEmail,
validPassword,
Expand All @@ -229,7 +214,6 @@ void shouldCreateUser() {
validInbox);

assertAll(
() -> assertEquals(validDisplayName, user.getDisplayName()),
() -> assertEquals(validUsername, user.getUsername()),
() -> assertEquals(validEmail, user.getEmail()),
() -> assertEquals(validRole, user.getRole()),
Expand Down

0 comments on commit b4448de

Please sign in to comment.