Skip to content

Commit

Permalink
fix: update tests and code to use new ParameterValidator error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Marjoni committed Apr 16, 2026
1 parent c350ee2 commit d9cfc51
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class OrganizationScraper {
* @return the description text, or null if not found or pageUrl is invalid
*/
public String fetchDescription(String pageUrl) {
if (descriptionCache.containsKey(pageUrl)) {
if (pageUrl != null && descriptionCache.containsKey(pageUrl)) {
return descriptionCache.get(pageUrl);
}

Expand Down Expand Up @@ -80,7 +80,7 @@ public String fetchDescription(String pageUrl) {
* @return the absolute logo URL, or null if not found or pageUrl is invalid
*/
public String fetchLogoUrl(String pageUrl) {
if (logoCache.containsKey(pageUrl)) {
if (pageUrl != null && logoCache.containsKey(pageUrl)) {
return logoCache.get(pageUrl);
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/edu/group5/app/model/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ public boolean registerUser(String role, String firstName, String lastName,
firstName == null || firstName.trim().isEmpty() ||
lastName == null || lastName.trim().isEmpty() ||
email == null || email.trim().isEmpty() ||
passwordHash == null || passwordHash.trim().isEmpty() ||
this.getUserByEmail(email) != null) {
passwordHash == null || passwordHash.trim().isEmpty()) {
return false;
}
User user;
Expand Down Expand Up @@ -95,7 +94,9 @@ public User login(String email, char[] password) {
* @return the User object if found, null otherwise
*/
public User getUserByEmail(String email) {
ParameterValidator.stringChecker(email, "email");
if (email == null || email.trim().isEmpty()) {
return null;
}
return this.userRepository.findUserByEmail(email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void setUp() {
void constructorThrowsIfNullList() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> new DonationRepository(null));
assertEquals("The list of rows cannot be null", ex.getMessage());
assertEquals("List of donation rows can't be null", ex.getMessage());
}

@Test
Expand Down Expand Up @@ -88,7 +88,7 @@ void addContentDuplicateIdFails() {
void addContentNullThrows() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> repo.addContent(null));
assertEquals("Donation cannot be null", ex.getMessage());
assertEquals("Donation can't be null", ex.getMessage());
}

@Test
Expand All @@ -102,7 +102,7 @@ void getDonationByIdSuccessfully() {
void getDonationByIdThrowsIfNegative() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> repo.getDonationById(0));
assertEquals("Donation ID must be positive", ex.getMessage());
assertEquals("Donation ID must be a positive integer", ex.getMessage());
}

@Test
Expand Down Expand Up @@ -182,7 +182,7 @@ void filterByOrganizationNoMatch() {
void filterByOrganizationThrowsIfNegative() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> repo.filterByOrganization(0));
assertEquals("Organization number must be positive", ex.getMessage());
assertEquals("Organization number must be a positive integer", ex.getMessage());
}

@Test
Expand Down Expand Up @@ -261,7 +261,7 @@ void filterByUserIdNoMatch() {
void filterByUserIdThrowsIfNegative() {
IllegalArgumentException ex = assertThrows(IllegalArgumentException.class,
() -> repo.filterByUser(0));
assertEquals("User ID must be positive", ex.getMessage());
assertEquals("User ID must be a positive integer", ex.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ void testConstructorThrowsIfDonationRepositoryIsNull() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
new DonationService(null, organizationRepository);
});
assertEquals("DonationRepository cannot be null", exception.getMessage());
assertEquals("DonationRepository can't be null", exception.getMessage());
}

@Test
void testConstructorThrowsIfOrganizationRepositoryIsNull() {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
new DonationService(donationRepository, null);
});
assertEquals("OrganizationRepository cannot be null", exception.getMessage());
assertEquals("OrganizationRepository can't be null", exception.getMessage());
}

@Test
Expand Down
Loading

0 comments on commit d9cfc51

Please sign in to comment.