Skip to content

Commit

Permalink
refactor: made the positive test for Organization more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
emilfa committed Mar 3, 2026
1 parent fbbdab4 commit 81a0a43
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
* <li>description must not be null</li>
* </ul>
*/
public record Organization(int orgNumber, String name, boolean trusted, String websiteURL, boolean isPreApproved,
String description) {
public record Organization(
int orgNumber,
String name,
boolean trusted,
String websiteURL,
boolean isPreApproved,
String description
) {
/**
* Creates a new organization.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,97 @@
import static org.junit.jupiter.api.Assertions.*;

class OrganizationTest {


@Test
void constructor_CreatesAnOrganizationWhenInputIsValid() {
Organization org = new Organization(
1,
"Org",
true,
"org.com",
true,
"Org description"
);

assertAll(
() -> assertEquals(1, org.orgNumber()),
() -> assertEquals("Org", org.name()),
() -> assertTrue(org.trusted()),
() -> assertEquals("org.com", org.websiteURL()),
() -> assertTrue(org.isPreApproved()),
() -> assertEquals("Org description", org.description())
);
}

@Test
void constructor_ThrowsWhenOrgNumberIsNegative() {
assertThrows(IllegalArgumentException.class, () -> {new Organization(
assertThrows(IllegalArgumentException.class, () -> new Organization(
-1,
"Org",
true,
null,
"org.com",
true,
"Org description"
);
});
));
}

@Test
void constructor_ThrowsWhenNameIsNull() {
assertThrows(NullPointerException.class, () -> {new Organization(
assertThrows(NullPointerException.class, () -> new Organization(
1,
null,
true,
"org.com",
true,
"Org description"
);
});
));
}

@Test
void constructor_ThrowsWhenNameIsBlank() {
assertThrows(IllegalArgumentException.class, () -> {new Organization(
assertThrows(IllegalArgumentException.class, () -> new Organization(
1,
"",
true,
"org.com",
true,
"Org description"
);
});
));
}

@Test
void constructor_ThrowsWhenWebsiteURLIsNull() {
assertThrows(NullPointerException.class, () -> {new Organization(
assertThrows(NullPointerException.class, () -> new Organization(
1,
"Org",
true,
null,
true,
"Org description"
);
});
));
}

@Test
void constructor_ThrowsWhenWebsiteURLIsBlank() {
assertThrows(IllegalArgumentException.class, () -> {new Organization(
assertThrows(IllegalArgumentException.class, () -> new Organization(
1,
"Org",
true,
"",
true,
"Org description"
);
});
));
}

@Test
void constructor_ThrowsWhenDescriptionIsNull() {
assertThrows(NullPointerException.class, () -> {new Organization(
assertThrows(NullPointerException.class, () -> new Organization(
1,
"Org",
true,
"org.com",
true,
null
);
});
));
}
}

0 comments on commit 81a0a43

Please sign in to comment.