From 6527929079f8321447172da73b9eb80b9da6e2a6 Mon Sep 17 00:00:00 2001 From: Roar Date: Thu, 23 Apr 2026 21:04:28 +0200 Subject: [PATCH] Updated MessageTest 100% coverage. --- .../team6/models/user/MessageTest.java | 147 ++++++++++++++++++ .../team6/models/user/MessegeTest.java | 44 ------ 2 files changed, 147 insertions(+), 44 deletions(-) create mode 100644 helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessageTest.java delete 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/MessageTest.java b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessageTest.java new file mode 100644 index 0000000..9b41b66 --- /dev/null +++ b/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessageTest.java @@ -0,0 +1,147 @@ +package ntnu.systemutvikling.team6.models.user; + +import static org.junit.jupiter.api.Assertions.*; +import java.time.LocalDate; +import java.util.UUID; +import ntnu.systemutvikling.team6.models.Charity; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +public class MessageTest { + private Charity charity; + + @BeforeEach + void setUp() { + charity = new Charity( + UUID.randomUUID().toString(), + "123", + false, + "approved"); + } + @Nested + class FirstConstructorTest { + @Test + void shouldThrowExceptionIfNameIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, + () -> new Message( + null, + charity, + "Something Somewhere Somehow")); + assertThrows( + IllegalArgumentException.class, + () -> new Message("", + charity, + "Something Somewhere Somehow")); + } + + @Test + void shouldThrowExceptionIfFromIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> new Message("Title", null, "Something Somewhere Somehow")); + } + + @Test + void shouldThrowExceptionIfContentIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, () -> new Message( + "Title", + charity, + null)); + assertThrows(IllegalArgumentException.class, () -> new Message( + "Title", + charity, + "")); + } + + @Test + void GettersWork() { + Message newMessage = new Message( + "Title", + charity, + "Somewhere"); + assertInstanceOf(UUID.class, newMessage.getId()); + assertEquals("Title", newMessage.getTitle()); + assertEquals(charity, newMessage.getFrom()); + assertEquals("Somewhere", newMessage.getContent()); + assertEquals(LocalDate.now(), newMessage.getTimeAndDate()); + } + } + + @Nested + class secondConstructorTest { + @Test + void shouldThrowExceptionIfNameIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, + () -> new Message( + null, + charity, + "Something Somewhere Somehow", + LocalDate.now())); + assertThrows( + IllegalArgumentException.class, + () -> new Message("", + charity, + "Something Somewhere Somehow", + LocalDate.now())); + } + + @Test + void shouldThrowExceptionIfFromIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> new Message( + "Title", + null, + "Something Somewhere Somehow", + LocalDate.now())); + } + + @Test + void shouldThrowExceptionIfContentIsNullOrEmpty() { + assertThrows( + IllegalArgumentException.class, () -> new Message( + "Title", + charity, + null, + LocalDate.now())); + assertThrows(IllegalArgumentException.class, () -> new Message( + "Title", + charity, + "", + LocalDate.now())); + } + + @Test + void shouldThrowExceptionIfDateIsNull() { + assertThrows( + IllegalArgumentException.class, + () -> new Message( + "Title", + charity, + "Something Somewhere Somehow", + null)); + } + + @Test + void GettersWork() { + Message newMessage = new Message( + "Title", + charity, + "Somewhere", + LocalDate.now()); + assertInstanceOf(UUID.class, newMessage.getId()); + assertEquals("Title", newMessage.getTitle()); + assertEquals(charity, newMessage.getFrom()); + assertEquals("Somewhere", newMessage.getContent()); + assertEquals(LocalDate.now(), newMessage.getTimeAndDate()); + } + + } + + + +} 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 deleted file mode 100644 index 1faa986..0000000 --- a/helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/user/MessegeTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package ntnu.systemutvikling.team6.models.user; - -import static org.junit.jupiter.api.Assertions.*; - -import java.time.LocalDate; -import java.util.UUID; -import org.junit.jupiter.api.Test; - -public class MessegeTest { - @Test - void shouldThrowExceptionIfNameIsNullOrEmpty() { - assertThrows( - IllegalArgumentException.class, - () -> new Message(null, UUID.randomUUID(), "Something Somewhere Somehow")); - assertThrows( - IllegalArgumentException.class, - () -> new Message("", UUID.randomUUID(), "Something Somewhere Somehow")); - } - - @Test - void shouldThrowExceptionIfFromIsNullOrEmpty() { - assertThrows( - IllegalArgumentException.class, - () -> new Message("Title", null, "Something Somewhere Somehow")); - } - - @Test - void shouldThrowExceptionIfContentIsNullOrEmpty() { - assertThrows( - IllegalArgumentException.class, () -> new Message("Title", UUID.randomUUID(), null)); - assertThrows(IllegalArgumentException.class, () -> new Message("Title", UUID.randomUUID(), "")); - } - - @Test - void GettersWork() { - UUID uuid = UUID.randomUUID(); - Message newMessage = new Message("Title", uuid, "Somewhere"); - assertInstanceOf(UUID.class, newMessage.getId()); - assertEquals("Title", newMessage.getTitle()); - assertEquals(uuid, newMessage.getFrom()); - assertEquals("Somewhere", newMessage.getContent()); - assertEquals(LocalDate.now(), newMessage.getTimeAndDate()); - } -}