Skip to content

Commit

Permalink
fix: fix Organizational classes by fixing constructor and JUnit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Marjoni committed Mar 4, 2026
1 parent dcc32bf commit adce116
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class OrganizationRepository extends Repository<Integer, Organization> {
private final HashMap<Integer, Organization> grandMap;

public OrganizationRepository(Object[] input) {
if (input == null) {
throw new IllegalArgumentException("The input cannot be null");
}
grandMap = new HashMap<>();
ObjectMapper mapper = new ObjectMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import edu.group5.app.model.user.Customer;

import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -14,24 +15,49 @@ class OrganizationRepositoryTest {

@BeforeEach
void setUp() {
Map<Integer, Organization> content = new HashMap<>();

Organization trustedOrganization1 = new Organization(1, "Trusted Org1", true, "org.com", true, "description");
Organization trustedOrganization2 = new Organization(2, "Trusted Org2", true, "org.com", true, "description");
Organization untrustedOrganization1 = new Organization(3, "Untrusted Org1", false, "org.com", true, "description");
Organization untrustedOrganization2 = new Organization(4, "Untrusted Org2", false, "org.com", true, "description");

content.put(1, trustedOrganization1);
content.put(2, trustedOrganization2);
content.put(3, untrustedOrganization1);
content.put(4, untrustedOrganization2);

Object[] content = new Object[] {
Map.of(
"org_number", "1",
"name", "Trusted Org1",
"status", "approved",
"url", "org.com",
"is_pre_approved", true
),
Map.of(
"org_number", "2",
"name", "Trusted Org2",
"status", "approved",
"url", "org.com",
"is_pre_approved", true
),
Map.of(
"org_number", "3",
"name", "Untrusted Org1",
"status", "pending",
"url", "org.com",
"is_pre_approved", true
),
Map.of(
"org_number", "4",
"name", "Untrusted Org2",
"status", "pending",
"url", "org.com",
"is_pre_approved", true
)
};
repository = new OrganizationRepository(content);
}

private void constructorTest(Object[] input, String expectedMessage) {
IllegalArgumentException exception = assertThrows(
IllegalArgumentException.class,
() -> new OrganizationRepository(input)
);
assertEquals(expectedMessage, exception.getMessage());
}
@Test
void constructor_ThrowsWhenContentIsNull() {
assertThrows(NullPointerException.class, () -> new OrganizationRepository(null));
constructorTest(null, "The input cannot be null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void constructor_CreatesAnOrganizationWhenInputIsValid() {
assertAll(
() -> assertEquals(1, org.orgNumber()),
() -> assertEquals("Org", org.name()),
() -> assertTrue(org.status()),
() -> assertTrue(org.trusted()),
() -> assertEquals("org.com", org.websiteURL()),
() -> assertTrue(org.isPreApproved()),
() -> assertEquals("Org description", org.description())
Expand Down

0 comments on commit adce116

Please sign in to comment.