Skip to content

Commit

Permalink
feat: made Organization into a record class + error handling + javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
emilfa committed Feb 26, 2026
1 parent 530223b commit 51a85e6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
67 changes: 36 additions & 31 deletions src/main/java/edu/group5/app/model/organization/Organization.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,49 @@

import java.util.Objects;

public class Organization {
private final int orgNumber;
private final String name;
private final boolean trusted;
private final String websiteURL;
private final boolean isPreApproved;
private final String description;

/**
* Represents an organization.
*
* <p>An organization is identified by an organization number, a name,
* trust status, website URL, pre-approval status, and a textual description.
*
* <p>Instances are validated on creation:
* <ul>
* <li>orgNumber must be non-negative</li>
* <li>name and websiteURL must not be null or blank</li>
* <li>description must not be null</li>
* </ul>
*/
public record Organization(int orgNumber, String name, boolean trusted, String websiteURL, boolean isPreApproved,
String description) {
/**
* Creates a new organization.
*
* @param orgNumber the organization number; must be non-negative
* @param name the organization name; must not be null or blank
* @param trusted whether the organization is trusted
* @param websiteURL the organization's website URL; must not be null or blank
* @param isPreApproved whether the organization is pre-approved
* @param description a textual description of the organization; must not be null
* @throws NullPointerException if name, websiteURL or description is null
* @throws IllegalArgumentException if orgNumber is negative, or if name or websiteURL is blank
*/
public Organization(int orgNumber, String name, boolean trusted, String websiteURL, boolean isPreApproved, String description) {
if (orgNumber < 0) {
throw new IllegalArgumentException("orgNumber cannot be negative");
}
this.orgNumber = orgNumber;
this.name = Objects.requireNonNull(name, "name cannot be null");
this.trusted = trusted;
this.websiteURL = Objects.requireNonNull(websiteURL, "websiteURL cannot be null");
this.isPreApproved = isPreApproved;
this.description = Objects.requireNonNull(description, "description cannot be null");
}

public int getOrgNumber() {
return orgNumber;
}

public String getName() {
return name;
}

public boolean isTrusted() {
return trusted;
}

public String getWebsiteURL() {
return websiteURL;
}

public boolean isPreApproved() {
return isPreApproved;
}

public String getDescription() {
return description;
if (name.isBlank()) {
throw new IllegalArgumentException("name cannot be blank");
}
if (websiteURL.isBlank()) {
throw new IllegalArgumentException("websiteURL cannot be blank");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import static org.junit.jupiter.api.Assertions.*;
class OrganizationTest {

}

0 comments on commit 51a85e6

Please sign in to comment.