-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/organizationRepo' into feat/organisation
- Loading branch information
Showing
17 changed files
with
122 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package edu.group5.app.model; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Represents a repository | ||
| */ | ||
| public abstract class Repository<K, V> { | ||
| protected final Map<K, V> content; | ||
|
|
||
| public Repository(Map<K, V> content) { | ||
| this.content = content; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the content of the repo | ||
| * @return content of the repo | ||
| */ | ||
| public Map<K, V> getContent() { | ||
| return content; | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
src/main/java/edu/group5/app/model/organization/OrganizationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package edu.group5.app.model.organization; | ||
|
|
||
| import edu.group5.app.model.Repository; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * Handles the business logic associated with organizations | ||
| */ | ||
| public class OrganizationRepository extends Repository<Integer, Organization> { | ||
| /** | ||
| * Creates a new Organization Repository | ||
| * | ||
| * @param content holds all current organizations in the repository; must not be null | ||
| * @throws NullPointerException if content is null | ||
| */ | ||
| public OrganizationRepository(Map<Integer, Organization> content) { | ||
| super(Objects.requireNonNull(content, "content cannot be null")); | ||
| } | ||
|
|
||
| /** | ||
| * Gets all trusted organizations in the repository | ||
| * @return all organizations with trusted = true | ||
| */ | ||
| public Map<Integer, Organization> getTrustedOrganizations() { | ||
| Map<Integer, Organization> trustedOrganizations = new HashMap<>(); | ||
|
|
||
| content.forEach((orgNr, org) -> { | ||
| if (org.trusted()) { | ||
| trustedOrganizations.put(orgNr, org); | ||
| } | ||
| }); | ||
|
|
||
| return trustedOrganizations; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/test/java/edu/group5/app/model/organization/OrganizationRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| 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 OrganizationRepository repository; | ||
|
|
||
| @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); | ||
|
|
||
| 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)); | ||
| } | ||
| } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed
BIN
-329 Bytes
target/classes/edu/group5/app/model/organization/Organization.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion
1
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst
This file was deleted.
Oops, something went wrong.
Binary file not shown.