diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java new file mode 100644 index 0000000..c96da2c --- /dev/null +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java @@ -0,0 +1,115 @@ +package ntnu.sytemutvikling.team6.models; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.time.LocalDateTime; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +class DonationTest { + private Settings settings; + private User User; + private Charity charity; + + // -- Setup -- + @BeforeEach + public void setup(){ + charity = new Charity("name", "something somewhere somehow", "Meow"); + User = new User() + } + + + // --- Tests --- + @Test + void testDonationInitialization() { + Charity charity = new Charity(); + User user = new User(new UserSettings(true)); + LocalDateTime now = LocalDateTime.now(); + + Donation donation = new Donation(500.0, now, charity, user); + + assertNotNull(donation.getCharityId()); + assertEquals(500.0, donation.getAmount()); + assertEquals(now, donation.getDate()); + assertEquals(charity, donation.getCharity()); + assertEquals(user, donation.getDonor()); + } + + @Test + void testAnonymousFlagWhenUserIsAnonymous() { + User user = new User(new UserSettings(true)); + Charity charity = new Charity(); + Donation donation = new Donation(100, LocalDateTime.now(), charity, user); + + // According to your logic: + // if donor.getSettings().isAnonymous() == false → donation.isAnonymous = true + // else → donation.isAnonymous = false + // + // So if user.isAnonymous() == true → donation.isAnonymous should be false + assertFalse(donation.isAnonymous()); + } + + @Test + void testAnonymousFlagWhenUserIsNotAnonymous() { + User user = new User(new UserSettings(false)); + Charity charity = new Charity(); + Donation donation = new Donation(100, LocalDateTime.now(), charity, user); + + // If user.isAnonymous() == false → donation.isAnonymous = true + assertTrue(donation.isAnonymous()); + } + + @Test + void testCharityIdIsUnique() { + Charity charity = new Charity(); + User user = new User(new UserSettings(true)); + + Donation d1 = new Donation(50, LocalDateTime.now(), charity, user); + Donation d2 = new Donation(75, LocalDateTime.now(), charity, user); + + assertNotEquals(d1.getCharityId(), d2.getCharityId()); + } + + @Test + void testAmountStoredCorrectly() { + Charity charity = new Charity(); + User user = new User(new UserSettings(true)); + + Donation donation = new Donation(123.45, LocalDateTime.now(), charity, user); + + assertEquals(123.45, donation.getAmount()); + } + + @Test + void testDateStoredCorrectly() { + LocalDateTime date = LocalDateTime.of(2024, 5, 10, 12, 30); + Charity charity = new Charity(); + User user = new User(new UserSettings(true)); + + Donation donation = new Donation(200, date, charity, user); + + assertEquals(date, donation.getDate()); + } + + @Test + void testCharityStoredCorrectly() { + Charity charity = new Charity(); + User user = new User(new UserSettings(true)); + + Donation donation = new Donation(200, LocalDateTime.now(), charity, user); + + assertEquals(charity, donation.getCharity()); + } + + @Test + void testDonorStoredCorrectly() { + Charity charity = new Charity(); + User user = new User(new UserSettings(true)); + + Donation donation = new Donation(200, LocalDateTime.now(), charity, user); + + assertEquals(user, donation.getDonor()); + } +} \ No newline at end of file