-
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 5, 2026
1 parent
4ef68e8
commit b13d42d
Showing
1 changed file
with
91 additions
and
0 deletions.
There are no files selected for viewing
91 changes: 91 additions & 0 deletions
91
helpmehelpapplication/src/test/java/ntnu/systemutvikling/team6/models/FeedbackTest.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,91 @@ | ||
| package ntnu.systemutvikling.team6.models; | ||
|
|
||
| import ntnu.sytemutvikling.team6.models.Settings; | ||
| import ntnu.sytemutvikling.team6.models.User; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| class FeedbackTest { | ||
|
|
||
| private User user; | ||
| private Settings settings; | ||
|
|
||
| // -- Setup -- | ||
| @BeforeEach | ||
| public void setup() { | ||
| settings = new Settings(true); // default anonymous = true | ||
| user = new User(); | ||
| } | ||
|
|
||
| // --- Tests --- | ||
|
|
||
| @Test | ||
| void testFeedbackInitialization() { | ||
| LocalDateTime before = LocalDateTime.now(); | ||
| Feedback feedback = new Feedback(user, "Nice work!"); | ||
| LocalDateTime after = LocalDateTime.now(); | ||
|
|
||
| assertNotNull(feedback.getFeedbackId()); | ||
| assertEquals("Nice work!", feedback.getComment()); | ||
| assertEquals(user, feedback.getUser()); | ||
|
|
||
| // Date should be between before and after | ||
| assertTrue(!feedback.getDate().isBefore(before) && !feedback.getDate().isAfter(after)); | ||
| } | ||
|
|
||
| @Test | ||
| void testAnonymousFlagWhenUserIsAnonymous() { | ||
| // user.settings.isAnonymous() == true → feedback.isAnonymous = false | ||
| settings = new UserSettings(true); | ||
| user = new User(settings); | ||
|
|
||
| Feedback feedback = new Feedback(user, "Anonymous feedback"); | ||
|
|
||
| assertFalse(feedback.isAnonymous()); | ||
| } | ||
|
|
||
| @Test | ||
| void testAnonymousFlagWhenUserIsNotAnonymous() { | ||
| // user.settings.isAnonymous() == false → feedback.isAnonymous = true | ||
| settings = new UserSettings(false); | ||
| user = new User(settings); | ||
|
|
||
| Feedback feedback = new Feedback(user, "Not anonymous"); | ||
|
|
||
| assertTrue(feedback.isAnonymous()); | ||
| } | ||
|
|
||
| @Test | ||
| void testFeedbackIdIsUnique() { | ||
| Feedback f1 = new Feedback(user, "First"); | ||
| Feedback f2 = new Feedback(user, "Second"); | ||
|
|
||
| assertNotEquals(f1.getFeedbackId(), f2.getFeedbackId()); | ||
| } | ||
|
|
||
| @Test | ||
| void testCommentStoredCorrectly() { | ||
| Feedback feedback = new Feedback(user, "This is a test comment"); | ||
|
|
||
| assertEquals("This is a test comment", feedback.getComment()); | ||
| } | ||
|
|
||
| @Test | ||
| void testUserStoredCorrectly() { | ||
| Feedback feedback = new Feedback(user, "Hello"); | ||
|
|
||
| assertEquals(user, feedback.getUser()); | ||
| } | ||
|
|
||
| @Test | ||
| void testDateIsSet() { | ||
| Feedback feedback = new Feedback(user, "Testing date"); | ||
|
|
||
| assertNotNull(feedback.getDate()); | ||
| } | ||
| } |