forked from medeirosdev/API-MusicBlender-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForumControllerCreateForumIndexTest.java
More file actions
117 lines (97 loc) · 4.56 KB
/
ForumControllerCreateForumIndexTest.java
File metadata and controls
117 lines (97 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ********RoostGPT********
/*
Test generated by RoostGPT for test maven-music-github using AI Type Azure Open AI and AI Model gpt-5
ROOST_METHOD_HASH=createForumIndex_fec126ecbb
ROOST_METHOD_SIG_HASH=createForumIndex_d46662bc78
Scenario 1: Returns success message and persists forum with typical valid inputs
Details:
TestName: returnsSuccessMessageAndPersistsForumWhenValidInput
Description: Validates that when provided with a non-empty name, a non-empty description, and a positive userId, the method constructs a forum entry, persists it via ForumIndexRepository.save, and returns the fixed success message.
Execution:
Arrange: Set up a ForumController instance with ForumIndexRepository mocked to accept any ForumIndexModel; ensure LogRepository and ForumChatRepository are also mocked. Prepare inputs such as nameForum = "General", forumDescription = "General discussion", userId = 42.
Act: Invoke createForumIndex with the arranged inputs.
Assert:
- Assert that the returned value equals the exact string "Forum criado".
- Verify that ForumIndexRepository.save is called exactly once with any ForumIndexModel instance.
- Verify that there are no interactions with LogRepository and ForumChatRepository.
Validation:
Confirms that the method’s primary behavior is to save a newly constructed forum and return a static success message. Ensures there are no side effects on unrelated components and that the method’s output is stable and predictable for valid input.
*/
// ********RoostGPT********
package com.medeiros.SPRINGProject.Controllers;
import com.medeiros.SPRINGProject.Models.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import com.medeiros.SPRINGProject.Controllers.ForumController;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.*;
@ExtendWith(MockitoExtension.class)
public class ForumControllerCreateForumIndexTest {
@Mock
private LogRepository Log;
@Mock
private ForumIndexRepository ForumIndexRepo;
@Mock
private ForumChatRepository ChatRepository;
@InjectMocks
private ForumController forumController;
@Test
@Tag("valid")
public void testReturnsSuccessMessageAndPersistsForumWhenValidInput() {
String nameForum = "General";
String forumDescription = "General discussion";
int userId = 42;
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}
@Test
@Tag("boundary")
public void testReturnsSuccessMessageAndPersistsForumWhenUserIdIsZero() {
String nameForum = "General";
String forumDescription = "General discussion";
int userId = 0;
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}
@Test
@Tag("invalid")
public void testReturnsSuccessMessageAndPersistsForumWhenUserIdIsNegative() {
String nameForum = "General";
String forumDescription = "General discussion";
int userId = -5; // TODO: Adjust if negative userId should be handled differently
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}
@Test
@Tag("boundary")
public void testReturnsSuccessMessageAndPersistsForumWhenNameAndDescriptionAreEmpty() {
String nameForum = "";
String forumDescription = "";
int userId = 7;
String actual = forumController.createForumIndex(nameForum, forumDescription, userId);
String expected = "Forum criado";
assertEquals((String) expected, (String) actual);
verify(ForumIndexRepo, times(1)).save(any(ForumIndexModel.class));
verifyNoMoreInteractions(ForumIndexRepo);
verifyNoInteractions(Log, ChatRepository);
}
}