Skip to content

Commit

Permalink
test: created tests for the OrganizationRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
emilfa committed Mar 1, 2026
1 parent 0523bce commit ee4a9ca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package edu.group5.app.model.organization;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.*;

class OrganizationRepositoryTest {

private Map<Integer, Organization> content;
private Organization trustedOrganization1;
private Organization trustedOrganization2;
private Organization untrustedOrganization1;
private Organization untrustedOrganization2;
private OrganizationRepository repository;

@BeforeEach
void setUp() {
content = new HashMap<>();

trustedOrganization1 =
new Organization(1, "Trusted Org1", true, "org.com", true, "description");
trustedOrganization2 =
new Organization(2, "Trusted Org2", true, "org.com", true, "description");
untrustedOrganization1 =
new Organization(3, "Untrusted Org1", false, "org.com", true, "description");
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);

repository = new OrganizationRepository(content);
}

@Test
void constructor_ThrowsWhenContentIsNull() {
assertThrows(NullPointerException.class, () -> new OrganizationRepository(null));
}

@Test
void getTrustedOrganizations_OnlyReturnsTrustedOrganizations() {
Map<Integer, Organization> trusted = repository.getTrustedOrganizations();

assertEquals(2, trusted.size());
assertTrue(trusted.containsKey(1));
assertTrue(trusted.containsKey(2));
assertFalse(trusted.containsKey(3));
assertFalse(trusted.containsKey(4));
assertTrue(trusted.values().stream().allMatch(Organization::trusted));
}
}

0 comments on commit ee4a9ca

Please sign in to comment.