forked from medeirosdev/API-MusicBlender-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAccountControllerDeleteUserByIdTest.java
More file actions
115 lines (93 loc) · 3.95 KB
/
UserAccountControllerDeleteUserByIdTest.java
File metadata and controls
115 lines (93 loc) · 3.95 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
// ********RoostGPT********
/*
Test generated by RoostGPT for test maven-music-github using AI Type Azure Open AI and AI Model gpt-5
ROOST_METHOD_HASH=deleteUserById_d65ace15d7
ROOST_METHOD_SIG_HASH=deleteUserById_91ecd15d81
Scenario 1: Successfully deletes when ID is a valid numeric string
Details:
TestName: deletesUserWhenValidNumericId
Description: Verifies that when a valid numeric string (e.g., "123") is provided, the method parses it, calls UserAccRepo.deleteById with the correct integer value, and returns the expected success message.
Execution:
Arrange: Set up a UserAccountController with a mock UserAccRepository that does not throw on deleteById, and mock UserInfoRepository and LogRepository.
Act: Call deleteUserById with "123".
Assert: Check that the returned string equals "Conta Deletada" and that UserAccRepo.deleteById was invoked exactly once with 123. Also verify no interactions with UserInfoRepo or Log.
Validation:
Confirms the primary happy path: valid input leads to a delete call and a fixed success message. Ensures the method uses only UserAccRepo for this operation and returns the literal Portuguese message as designed.
*/
// ********RoostGPT********
package com.medeiros.SPRINGProject.Controllers;
import com.medeiros.SPRINGProject.Controllers.UserAccountController;
import com.medeiros.SPRINGProject.Models.*;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.*;
@ExtendWith(MockitoExtension.class)
public class UserAccountControllerDeleteUserByIdTest {
@InjectMocks
private UserAccountController controller;
@Mock
private UserAccRepository UserAccRepo;
@Mock
private UserInfoRepository UserInfoRepo;
@Mock
private LogRepository Log;
@Test
@Tag("valid")
public void testDeletesUserWhenValidNumericId() {
String inputId = "123";
String result = controller.deleteUserById(inputId);
assertEquals((String) "Conta Deletada", (String) result);
verify(UserAccRepo, times(1)).deleteById(123);
verifyNoInteractions(UserInfoRepo, Log);
}
@Test
@Tag("boundary")
public void testDeleteUserWithZeroId() {
String inputId = "0";
String result = controller.deleteUserById(inputId);
assertEquals((String) "Conta Deletada", (String) result);
verify(UserAccRepo, times(1)).deleteById(0);
verifyNoInteractions(UserInfoRepo, Log);
}
@Test
@Tag("boundary")
public void testDeleteUserWithNegativeId() {
String inputId = "-1";
String result = controller.deleteUserById(inputId);
assertEquals((String) "Conta Deletada", (String) result);
verify(UserAccRepo, times(1)).deleteById(-1);
verifyNoInteractions(UserInfoRepo, Log);
}
@Test
@Tag("invalid")
public void testDeleteUserWithNonNumericIdThrowsNumberFormatException() {
String inputId = "abc"; // TODO: Replace with other non-numeric strings if needed
assertThrows(NumberFormatException.class, () -> controller.deleteUserById(inputId));
verifyNoInteractions(UserAccRepo, UserInfoRepo, Log);
}
@Test
@Tag("invalid")
public void testDeleteUserWithWhitespaceOnlyThrowsNumberFormatException() {
String inputId = " 123 "; // TODO: Replace with other whitespace formats if needed
assertThrows(NumberFormatException.class, () -> controller.deleteUserById(inputId));
verifyNoInteractions(UserAccRepo, UserInfoRepo, Log);
}
@Test
@Tag("invalid")
public void testDeleteUserWithNullIdThrowsNumberFormatException() {
String inputId = null;
assertThrows(NumberFormatException.class, () -> controller.deleteUserById(inputId));
verifyNoInteractions(UserAccRepo, UserInfoRepo, Log);
}
}