Skip to content

Commit

Permalink
Fix: Package Placement
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBalunan committed Mar 5, 2026
1 parent 40c5bed commit 98feae9
Show file tree
Hide file tree
Showing 23 changed files with 519 additions and 605 deletions.
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));
}
}
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());
}
}
Loading

0 comments on commit 98feae9

Please sign in to comment.