-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt Feat: DonationTest but User is fully developed
- Loading branch information
AdrianBalunan
committed
Mar 4, 2026
1 parent
0baccdd
commit 7d6fe90
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/DonationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()); | ||
| } | ||
| } |