diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java index 37b7013..17f495d 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/Inbox.java @@ -6,7 +6,7 @@ // Enhetstester mangler /** - * Represents a users inbox that contains messages. + * Represents a user's inbox that contains messages. * Provides methods to add, remove and get messages. * * @author Robin Strand Prestmo @@ -24,7 +24,7 @@ public Inbox() { /** * Returns an unmodifiable view of the messages in this inbox. * - * @return an unmodifiable list of messages. + * @return an unmodifiable list of messages */ public List getMessages() { return Collections.unmodifiableList(messages); @@ -33,8 +33,9 @@ public List getMessages() { /** * Finds a specific message by id. * - * @param messageId is the ID to the message that is searching after. - * @return message with matching id if the id exists. + * @param messageId the id of the message to search for + * @return messageId the id of the message to remove + * @throws IllegalArgumentException if messageId is null */ public Optional findMessageById(UUID messageId) { if (messageId == null) { @@ -47,8 +48,12 @@ public Optional findMessageById(UUID messageId) { * Add´s message to the messages list. * * @param message to be added + * @throws IllegalArgumentException if message is null */ public void addMessage(Message message) { + if (message == null) { + throw new IllegalArgumentException("Message cannot be null"); + } messages.add(message); } @@ -56,9 +61,13 @@ public void addMessage(Message message) { * Removes a message from the inbox list. * * @param messageId the id to the message to be removed - * @return true if the message was removed, false if not found. + * @return true if the message was removed, false if not found + * @throws IllegalArgumentException if messageId is null */ public boolean removeMessage(UUID messageId) { + if (messageId == null) { + throw new IllegalArgumentException("MessageId cannot be null"); + } return messages.removeIf(message -> messageId.equals(message.getId())); } }