-
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.
- Loading branch information
AdrianBalunan
committed
Mar 16, 2026
1 parent
ccf109b
commit 44b90d3
Showing
1 changed file
with
95 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/InboxTest.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,95 @@ | ||
| package ntnu.systemutvikling.team6.models.user; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| public class InboxTest { | ||
| private Inbox inbox; | ||
| private Message newMessage; | ||
| private Message newMessage2; | ||
|
|
||
| @BeforeEach | ||
| public void setup(){ | ||
| inbox = new Inbox(); | ||
| newMessage = new Message("Title", "Someone", "Somewhere"); | ||
| newMessage2 = new Message("Title2", "Someone2", "Somewhere2"); | ||
| } | ||
|
|
||
| @Test | ||
| void constructor_shouldCreateEmptyInbox() { | ||
| assertTrue(inbox.getMessages().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void addMessage_shouldAddMessageToInbox() { | ||
| inbox.addMessage(newMessage); | ||
|
|
||
| List<Message> messages = inbox.getMessages(); | ||
| assertEquals(1, messages.size()); | ||
| assertTrue(messages.contains(newMessage)); | ||
| } | ||
|
|
||
| @Test | ||
| void addMessage_nullMessage_shouldThrowException() { | ||
| assertThrows(IllegalArgumentException.class, () -> inbox.addMessage(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void getMessages_shouldReturnUnmodifiableList() { | ||
| inbox.addMessage(newMessage); | ||
|
|
||
| List<Message> messages = inbox.getMessages(); | ||
|
|
||
| assertThrows(UnsupportedOperationException.class, () -> messages.add(newMessage2)); | ||
| } | ||
|
|
||
| @Test | ||
| void findMessageById_shouldReturnMessageWhenFound() { | ||
| inbox.addMessage(newMessage); | ||
|
|
||
| Optional<Message> result = inbox.findMessageById(newMessage.getId()); | ||
|
|
||
| assertTrue(result.isPresent()); | ||
| assertEquals(newMessage, result.get()); | ||
| } | ||
|
|
||
| @Test | ||
| void findMessageById_shouldReturnEmptyWhenNotFound() { | ||
| Optional<Message> result = inbox.findMessageById(UUID.randomUUID()); | ||
|
|
||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void findMessageById_nullId_shouldThrowException() { | ||
| assertThrows(IllegalArgumentException.class, () -> inbox.findMessageById(null)); | ||
| } | ||
|
|
||
| @Test | ||
| void removeMessage_shouldRemoveExistingMessage() { | ||
| inbox.addMessage(newMessage); | ||
|
|
||
| boolean removed = inbox.removeMessage(newMessage.getId()); | ||
|
|
||
| assertTrue(removed); | ||
| assertTrue(inbox.getMessages().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void removeMessage_shouldReturnFalseIfNotFound() { | ||
| boolean removed = inbox.removeMessage(UUID.randomUUID()); | ||
|
|
||
| assertFalse(removed); | ||
| } | ||
|
|
||
| @Test | ||
| void removeMessage_nullId_shouldThrowException() { | ||
| assertThrows(IllegalArgumentException.class, () -> inbox.removeMessage(null)); | ||
| } | ||
| } |