-
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.
- Loading branch information
AdrianBalunan
committed
Mar 5, 2026
1 parent
40c5bed
commit 98feae9
Showing
23 changed files
with
519 additions
and
605 deletions.
There are no files selected for viewing
157 changes: 77 additions & 80 deletions
157
...ehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.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 |
|---|---|---|
| @@ -1,94 +1,91 @@ | ||
| package ntnu.systemutvikling.team6.models; | ||
|
|
||
| import ntnu.sytemutvikling.team6.models.Charity; | ||
| import ntnu.sytemutvikling.team6.models.CharityRegistry; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
| import ntnu.sytemutvikling.team6.models.Charity; | ||
| import ntnu.sytemutvikling.team6.models.CharityRegistry; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * UnitTest for CharityRegistry class | ||
| * | ||
| * @author Adrian Balunan | ||
| */ | ||
|
|
||
| public class CharityRegistryTest { | ||
| private CharityRegistry registry; | ||
| private Charity charity; | ||
|
|
||
| /* Setting up variables */ | ||
| @BeforeEach | ||
| public void setup(){ | ||
| registry = new CharityRegistry(); | ||
| charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void testAddCharitySuccessfully() { | ||
| registry.addCharity(charity); | ||
|
|
||
| assertEquals(1, registry.getAllCharities().size()); | ||
| assertTrue(registry.getAllCharities().contains(charity)); | ||
| } | ||
|
|
||
| @Test | ||
| void testAddCharityNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> registry.addCharity(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetAllCharitiesReturnsUnmodifiableList() { | ||
| registry.addCharity(charity); | ||
|
|
||
| List<Charity> charities = registry.getAllCharities(); | ||
| assertThrows(UnsupportedOperationException.class, () -> charities.add(charity)); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindCharityByIdFound() { | ||
| registry.addCharity(charity); | ||
|
|
||
| Optional<Charity> result = registry.findCharityById(charity.getId()); | ||
|
|
||
| assertTrue(result.isPresent()); | ||
| assertEquals(charity, result.get()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindCharityByIdNotFound() { | ||
| Optional<Charity> result = registry.findCharityById(UUID.randomUUID()); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindCharityByIdNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> registry.findCharityById(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveCharitySuccessfully() { | ||
| registry.addCharity(charity); | ||
|
|
||
| boolean removed = registry.removeCharity(charity.getId()); | ||
|
|
||
| assertTrue(removed); | ||
| assertTrue(registry.getAllCharities().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveCharityNotFound() { | ||
| boolean removed = registry.removeCharity(UUID.randomUUID()); | ||
| assertFalse(removed); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveCharityNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> registry.removeCharity(null)); | ||
| } | ||
| private CharityRegistry registry; | ||
| private Charity charity; | ||
|
|
||
| /* Setting up variables */ | ||
| @BeforeEach | ||
| public void setup() { | ||
| registry = new CharityRegistry(); | ||
| charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); | ||
| } | ||
|
|
||
| @Test | ||
| void testAddCharitySuccessfully() { | ||
| registry.addCharity(charity); | ||
|
|
||
| assertEquals(1, registry.getAllCharities().size()); | ||
| assertTrue(registry.getAllCharities().contains(charity)); | ||
| } | ||
|
|
||
| @Test | ||
| void testAddCharityNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> registry.addCharity(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void testGetAllCharitiesReturnsUnmodifiableList() { | ||
| registry.addCharity(charity); | ||
|
|
||
| List<Charity> charities = registry.getAllCharities(); | ||
| assertThrows(UnsupportedOperationException.class, () -> charities.add(charity)); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindCharityByIdFound() { | ||
| registry.addCharity(charity); | ||
|
|
||
| Optional<Charity> result = registry.findCharityById(charity.getId()); | ||
|
|
||
| assertTrue(result.isPresent()); | ||
| assertEquals(charity, result.get()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindCharityByIdNotFound() { | ||
| Optional<Charity> result = registry.findCharityById(UUID.randomUUID()); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFindCharityByIdNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> registry.findCharityById(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveCharitySuccessfully() { | ||
| registry.addCharity(charity); | ||
|
|
||
| boolean removed = registry.removeCharity(charity.getId()); | ||
|
|
||
| assertTrue(removed); | ||
| assertTrue(registry.getAllCharities().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveCharityNotFound() { | ||
| boolean removed = registry.removeCharity(UUID.randomUUID()); | ||
| assertFalse(removed); | ||
| } | ||
|
|
||
| @Test | ||
| void testRemoveCharityNullThrowsException() { | ||
| assertThrows(IllegalArgumentException.class, () -> registry.removeCharity(null)); | ||
| } | ||
| } |
104 changes: 49 additions & 55 deletions
104
helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.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 |
|---|---|---|
| @@ -1,68 +1,62 @@ | ||
| package ntnu.systemutvikling.team6.models; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.util.UUID; | ||
| import ntnu.sytemutvikling.team6.models.Charity; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
| * UnitTesting for Charity. | ||
| * | ||
| * @author Adrian Balunan | ||
| */ | ||
| public class CharityTest { | ||
| private Charity charity; | ||
|
|
||
| @BeforeEach | ||
| public void setup(){ | ||
| charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); | ||
| } | ||
|
|
||
| /** | ||
| * Getters should work: | ||
| */ | ||
| @Test | ||
| public void testGettingIdShouldWork(){ | ||
| assertInstanceOf(UUID.class, charity.getId()); | ||
| } | ||
| @Test | ||
| public void testGettingCategoryShouldWork(){ | ||
| assertEquals("Cancer", charity.getCategory()); | ||
| } | ||
| @Test | ||
| public void testGettingNameShouldWork(){ | ||
| assertEquals( "Charity1",charity.getName()); | ||
| } | ||
| @Test | ||
| public void testGettingDescriptionShouldWork(){ | ||
| assertEquals("Something Somewhere Somehow",charity.getDescription()); | ||
| } | ||
|
|
||
| /** | ||
| * Getter and setter for IsVerified should be able to switch between true and false | ||
| */ | ||
| @Test | ||
| public void testIsVerifiedReturnsCorrectly(){ | ||
| assertFalse(charity.isVerified()); | ||
| charity.setVerified(); | ||
| assertTrue(charity.isVerified()); | ||
| charity.setUnverified(); | ||
| assertFalse(charity.isVerified()); | ||
| } | ||
|
|
||
| /** | ||
| * totalDonations should display accuratly and adding works | ||
| */ | ||
| @Test | ||
| public void testTotalDonationsReturnsCorrectlyAfterChanges(){ | ||
| assertEquals(0, charity.getTotalDonations()); | ||
| charity.setTotalDonations(10); | ||
| charity.setTotalDonations(5); | ||
| assertEquals(15, charity.getTotalDonations()); | ||
| } | ||
|
|
||
| private Charity charity; | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| charity = new Charity("Charity1", "Something Somewhere Somehow", "Cancer"); | ||
| } | ||
|
|
||
| /** Getters should work: */ | ||
| @Test | ||
| public void testGettingIdShouldWork() { | ||
| assertInstanceOf(UUID.class, charity.getId()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGettingCategoryShouldWork() { | ||
| assertEquals("Cancer", charity.getCategory()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGettingNameShouldWork() { | ||
| assertEquals("Charity1", charity.getName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGettingDescriptionShouldWork() { | ||
| assertEquals("Something Somewhere Somehow", charity.getDescription()); | ||
| } | ||
|
|
||
| /** Getter and setter for IsVerified should be able to switch between true and false */ | ||
| @Test | ||
| public void testIsVerifiedReturnsCorrectly() { | ||
| assertFalse(charity.isVerified()); | ||
| charity.setVerified(); | ||
| assertTrue(charity.isVerified()); | ||
| charity.setUnverified(); | ||
| assertFalse(charity.isVerified()); | ||
| } | ||
|
|
||
| /** totalDonations should display accuratly and adding works */ | ||
| @Test | ||
| public void testTotalDonationsReturnsCorrectlyAfterChanges() { | ||
| assertEquals(0, charity.getTotalDonations()); | ||
| charity.setTotalDonations(10); | ||
| charity.setTotalDonations(5); | ||
| assertEquals(15, charity.getTotalDonations()); | ||
| } | ||
| } |
Oops, something went wrong.