From 25b8580ca8c5de8391047d30130c88fedc2e6576 Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Sun, 15 Mar 2026 20:44:20 +0100 Subject: [PATCH] Fix: reinlisted tests and now should be working. Coverage will be done on a later date --- .../team6/database/DatabaseManager.java | 4 +- .../systemutvikling/team6/models/Charity.java | 2 +- .../team6/models/CharityRegistry.java | 4 +- .../src/main/resources/fxml/frontPage.fxml | 34 ++-- .../team6/models/CharityRegistryTest.java | 151 ++++++++++-------- .../team6/models/CharityTest.java | 30 ++-- 6 files changed, 122 insertions(+), 103 deletions(-) diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java index 43c4bef..6b85082 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/database/DatabaseManager.java @@ -95,8 +95,8 @@ PRIMARY KEY (`UUID_Donations`), CONSTRAINT `fk_Donations_Charities` FOREIGN KEY (`Charities_UUID_charities`) REFERENCES Charities (`UUID_charities`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) + ON DELETE CASCADE + ON UPDATE CASCADE) ENGINE = InnoDB; """; diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java index 4cdf03a..4f5a9ec 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/Charity.java @@ -112,7 +112,7 @@ public String getDescription() { /** Setter for verification status. This one sets the charity as verified. */ public void setVerified() { - this.status = "Approved"; + this.status = "approved"; } /** Setter for verification status. This one sets the charity as unverified. */ diff --git a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/CharityRegistry.java b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/CharityRegistry.java index b829a41..962b833 100644 --- a/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/CharityRegistry.java +++ b/helpmehelpapplication/src/main/java/ntnu/systemutvikling/team6/models/CharityRegistry.java @@ -24,9 +24,9 @@ public Optional findCharityByOrgnumber(String org_number) { public Optional findCharityByUUID(UUID uuid) { if (uuid == null) { - throw new IllegalArgumentException("CharityId can not be null."); + throw new IllegalArgumentException("Uuid can not be null."); } - return charities.stream().filter(charity -> uuid.equals(charity.getOrg_number())).findFirst(); + return charities.stream().filter(charity -> uuid.equals(charity.getUUID())).findFirst(); } public void addCharity(Charity charity) { diff --git a/helpmehelpapplication/src/main/resources/fxml/frontPage.fxml b/helpmehelpapplication/src/main/resources/fxml/frontPage.fxml index b9a76c6..93ed395 100644 --- a/helpmehelpapplication/src/main/resources/fxml/frontPage.fxml +++ b/helpmehelpapplication/src/main/resources/fxml/frontPage.fxml @@ -1,15 +1,27 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + - + @@ -211,7 +223,7 @@ - + @@ -274,7 +286,7 @@ - + diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java index 42f4667..1ac0261 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityRegistryTest.java @@ -1,4 +1,4 @@ -/* package ntnu.systemutvikling.team6.models; +package ntnu.systemutvikling.team6.models; import static org.junit.jupiter.api.Assertions.*; @@ -13,80 +13,89 @@ * * @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 charities = registry.getAllCharities(); - assertThrows(UnsupportedOperationException.class, () -> charities.add(charity)); - } - - @Test - void testFindCharityByIdFound() { - registry.addCharity(charity); - - Optional result = registry.findCharityByUUID(charity.getUUID()); - - assertTrue(result.isPresent()); - assertEquals(charity, result.get()); - } - - @Test - void testFindCharityByIdNotFound() { - Optional result = registry.findCharityByUUID(UUID.randomUUID()); - assertTrue(result.isEmpty()); - } - - @Test - void testFindCharityByIdNullThrowsException() { - assertThrows(IllegalArgumentException.class, () -> registry.findCharityByUUID(null)); - } - - @Test - void testRemoveCharitySuccessfully() { - registry.addCharity(charity); - - boolean removed = registry.removeCharityUUID(charity.getUUID()); - - assertTrue(removed); - assertTrue(registry.getAllCharities().isEmpty()); + @BeforeEach + public void setup() { + registry = new CharityRegistry(); + charity = new Charity("1239813", "www.aaaa.com", "Charity1", false, "unverified"); + + } + + @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 charities = registry.getAllCharities(); + assertThrows(UnsupportedOperationException.class, () -> charities.add(charity)); + } + + @Test + void testFindCharityByIdFound() { + registry.addCharity(charity); + + Optional result = registry.findCharityByUUID(charity.getUUID()); + + assertTrue(result.isPresent()); + assertEquals(charity, result.get()); + } + @Test + void testFindCharityByOrgNumber() { + registry.addCharity(charity); + + Optional result = registry.findCharityByOrgnumber(charity.getOrg_number()); + + assertTrue(result.isPresent()); + assertEquals(charity, result.get()); + } + + @Test + void testFindCharityByIdNotFound() { + Optional result = registry.findCharityByUUID(UUID.randomUUID()); + assertTrue(result.isEmpty()); + } + + @Test + void testFindCharityByIdNullThrowsException() { + assertThrows(IllegalArgumentException.class, () -> registry.findCharityByUUID(null)); + } + + @Test + void testRemoveCharitySuccessfully() { + registry.addCharity(charity); + + boolean removed = registry.removeCharityUUID(charity.getUUID()); + + assertTrue(removed); + assertTrue(registry.getAllCharities().isEmpty()); + } + + @Test + void testRemoveCharityNotFound() { + boolean removed = registry.removeCharityUUID(UUID.randomUUID()); + assertFalse(removed); + } + + @Test + void testRemoveCharityNullThrowsException() { + assertThrows(IllegalArgumentException.class, () -> registry.removeCharity(null)); + } } - @Test - void testRemoveCharityNotFound() { - boolean removed = registry.removeCharityUUID(UUID.randomUUID()); - assertFalse(removed); - } - - @Test - void testRemoveCharityNullThrowsException() { - assertThrows(IllegalArgumentException.class, () -> registry.removeCharity(null)); - } -} -*/ \ No newline at end of file diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java index 4f9c0e6..43fa905 100644 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/CharityTest.java @@ -1,4 +1,4 @@ -/* package ntnu.systemutvikling.team6.models; +package ntnu.systemutvikling.team6.models; import static org.junit.jupiter.api.Assertions.*; @@ -11,17 +11,16 @@ * * @author Adrian Balunan */ -/* + public class CharityTest { private Charity charity; @BeforeEach public void setup() { - charity = new Charity("1212", "Charity1", "Something Somewhere Somehow", "Cancer", false, "unverified"); + charity = new Charity("1239813", "www.aaaa.com", "Charity1", false, "unverified"); } /** Getters should work: */ - /* @Test public void testGettingIdShouldWork() { assertInstanceOf(UUID.class, charity.getUUID()); @@ -29,7 +28,7 @@ public void testGettingIdShouldWork() { @Test public void testGettingCategoryShouldWork() { - assertEquals("Cancer", charity.getCategory()); + assertEquals("", charity.getCategory()); } @Test @@ -39,18 +38,17 @@ public void testGettingNameShouldWork() { @Test public void testGettingDescriptionShouldWork() { - assertEquals("Something Somewhere Somehow", charity.getDescription()); + assertEquals("Les mer her: www.aaaa.com", charity.getDescription()); } /** Getter and setter for IsVerified should be able to switch between true and false */ - /* - @Test - public void testIsVerifiedReturnsCorrectly() { - assertFalse(charity.getPreApproved()); - charity.setVerified(); - assertTrue(charity.getPreApproved()); - charity.setUnverified(); - assertFalse(charity.getPreApproved()); + @Test + public void testIsVerifiedReturnsCorrectly() { + assertEquals("approved", charity.getStatus()); + charity.setUnverified(); + assertEquals("Veto", charity.getStatus()); + charity.setVerified(); + assertEquals("approved", charity.getStatus()); + } } -} - */ +