From ccf109bd7ba3ec0f27fabca5bef198915755c79d Mon Sep 17 00:00:00 2001 From: AdrianBalunan Date: Mon, 16 Mar 2026 18:11:14 +0100 Subject: [PATCH] Feat: Message Class test --- .../team6/models/user/MessegeTest.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java diff --git a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java new file mode 100644 index 0000000..ff71841 --- /dev/null +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java @@ -0,0 +1,50 @@ +package ntnu.systemutvikling.team6.models.user; + +import org.junit.jupiter.api.Test; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.*; + +public class MessegeTest { + @Test + void shouldThrowExceptionIfNameIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, + () -> new Message(null, "Someone", "Something Somewhere Somehow")); + assertThrows( + IllegalArgumentException.class, + () -> new Message("", "Someone", "Something Somewhere Somehow")); + } + + @Test + void shouldThrowExceptionIfFromIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, + () -> new Message("Title", null, "Something Somewhere Somehow")); + assertThrows( + IllegalArgumentException.class, + () -> new Message("Title", "", "Something Somewhere Somehow")); + } + @Test + void shouldThrowExceptionIfContentIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, + () -> new Message("Title", "Someone", null)); + assertThrows( + IllegalArgumentException.class, + () -> new Message("Title", "Someone", "")); + } + + @Test + void GettersWork(){ + Message newMessage = new Message("Title", "Someone", "Somewhere"); + assertInstanceOf(UUID.class, newMessage.getId()); + assertEquals("Title", newMessage.getTitle()); + assertEquals("Someone", newMessage.getFrom()); + assertEquals("Somewhere", newMessage.getContent()); + assertEquals(LocalDate.now(), newMessage.getTimeAndDate().toLocalDate()); + } +}