-
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.
100% coverage for UserRegistry.
- Loading branch information
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
...pplication/src/test/java/ntnu/systemutvikling/team6/models/registry/UserRegistryTest.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,106 @@ | ||
| package ntnu.systemutvikling.team6.models.registry; | ||
|
|
||
| import ntnu.systemutvikling.team6.models.user.Inbox; | ||
| import ntnu.systemutvikling.team6.models.user.Role; | ||
| import ntnu.systemutvikling.team6.models.user.Settings; | ||
| import ntnu.systemutvikling.team6.models.user.User; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class UserRegistryTest { | ||
| User user; | ||
| UserRegistry userRegistry; | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| String validUsername = "username"; | ||
| String validEmail = "Email@gmail.com"; | ||
| String validPassword = "Password"; | ||
| Role validRole = Role.NORMAL_USER; | ||
| Settings validSettings = new Settings(); | ||
| Inbox validInbox = new Inbox(); | ||
| this.user = | ||
| new User( | ||
| validUsername, | ||
| validEmail, | ||
| validPassword, | ||
| validRole, | ||
| validSettings, | ||
| validInbox | ||
| ); | ||
| userRegistry = new UserRegistry(); | ||
| } | ||
|
|
||
| @Test | ||
| void userRegistryShouldStartEmpty() { | ||
| assertEquals(0, userRegistry.getAllUsers().size()); | ||
| } | ||
|
|
||
| @Test | ||
| void addUserTest() { | ||
| userRegistry.addUser(user); | ||
|
|
||
| assertEquals(user, userRegistry.getAllUsers().getFirst()); | ||
| } | ||
|
|
||
| @Test | ||
| void addingNullUserShouldThrow() { | ||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> userRegistry.addUser(null) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void removeUserTest() { | ||
| userRegistry.addUser(user); | ||
|
|
||
| userRegistry.removeUserByUUID(user.getId()); | ||
|
|
||
| assertEquals(0, userRegistry.getAllUsers().size()); | ||
| } | ||
|
|
||
| @Test | ||
| void removeNullUserShouldThrow() { | ||
| userRegistry.addUser(user); | ||
|
|
||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> userRegistry.removeUserByUUID(null) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void getUserByUUIDTest() { | ||
| userRegistry.addUser(user); | ||
|
|
||
| Optional<User> result = userRegistry.findUserById(user.getId()); | ||
|
|
||
| assertTrue(result.isPresent()); | ||
| assertEquals(result.get().getId(), user.getId()); | ||
| } | ||
|
|
||
| @Test | ||
| void getUserByUUIDNonExistentUserTest() { | ||
| userRegistry.addUser(user); | ||
|
|
||
| Optional<User> result = userRegistry.findUserById(UUID.randomUUID()); | ||
|
|
||
| assertFalse(result.isPresent()); | ||
| } | ||
|
|
||
| @Test | ||
| void getNullUserByUUIDShouldThrow() { | ||
| userRegistry.addUser(user); | ||
|
|
||
| assertThrows( | ||
| IllegalArgumentException.class, | ||
| () -> userRegistry.findUserById(null) | ||
| ); | ||
| } | ||
| } |