diff --git a/src/main/java/edu/group5/app/model/donation/DonationRepository.java b/src/main/java/edu/group5/app/model/donation/DonationRepository.java index 596ea60..339e7ca 100644 --- a/src/main/java/edu/group5/app/model/donation/DonationRepository.java +++ b/src/main/java/edu/group5/app/model/donation/DonationRepository.java @@ -25,6 +25,9 @@ public class DonationRepository extends DBRepository { * where the key represents the donation ID */ public DonationRepository(HashMap content){ + if (content == null) { + throw new IllegalArgumentException("Content cannot be null"); + } super(content); this.content = content; } @@ -42,7 +45,10 @@ public DonationRepository(HashMap content){ * {@code false} if a donation with the same ID already exists */ public boolean addDonation(Donation donation) { - if(content.containsKey(donation.donationId())){ + if (donation == null) { + throw new IllegalArgumentException("Donation cannot be null"); + } + if (content.containsKey(donation.donationId())){ return false; } content.put(donation.donationId(), donation); @@ -97,6 +103,9 @@ public HashMap sortByAmount() { * @return a map containing all donations that belong to the given organization */ public HashMap filterByOrganization(int orgNumber) { + if (orgNumber <= 0) { + throw new IllegalArgumentException("Organization number must be positive"); + } return content.entrySet() .stream() .filter(entry -> entry.getValue().organizationId() == orgNumber)