Skip to content

Commit be162f6

Browse files
committed
test(person): fixes person list tests
1 parent f6b9f7e commit be162f6

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/test/java/com/github/renancvitor/inventory/controller/person/PersonControllerListTests.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ void shouldListWithoutFilters() {
7878

7979
lenient().when(personService.list(
8080
any(Pageable.class),
81+
isNull(),
8182
any(User.class),
8283
isNull()))
8384
.thenReturn(page);
8485

8586
ResponseEntity<CustomPage<PersonListingData>> response = personController.list(
8687
null,
87-
PageRequest.of(0, 10),
88+
PageRequest.of(0, 10), null,
8889
loggedInUser);
8990

9091
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -93,6 +94,7 @@ void shouldListWithoutFilters() {
9394
.isEqualTo(person.getPersonName());
9495
verify(personService).list(
9596
any(Pageable.class),
97+
isNull(),
9698
eq(loggedInUser),
9799
isNull());
98100
verifyNoMoreInteractions(personService);
@@ -107,13 +109,14 @@ void shouldListWithActiveTrue() {
107109

108110
lenient().when(personService.list(
109111
any(Pageable.class),
112+
isNull(),
110113
any(User.class),
111114
eq(true)))
112115
.thenReturn(page);
113116

114117
ResponseEntity<CustomPage<PersonListingData>> response = personController.list(
115118
true,
116-
PageRequest.of(0, 10),
119+
PageRequest.of(0, 10), null,
117120
loggedInUser);
118121

119122
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -122,6 +125,7 @@ void shouldListWithActiveTrue() {
122125
.isEqualTo(person.getPersonName());
123126
verify(personService).list(
124127
any(Pageable.class),
128+
isNull(),
125129
eq(loggedInUser),
126130
eq(true));
127131
verifyNoMoreInteractions(personService);
@@ -136,13 +140,14 @@ void shouldListWithActiveFalse() {
136140

137141
lenient().when(personService.list(
138142
any(Pageable.class),
143+
isNull(),
139144
any(User.class),
140145
eq(false)))
141146
.thenReturn(page);
142147

143148
ResponseEntity<CustomPage<PersonListingData>> response = personController.list(
144149
false,
145-
PageRequest.of(0, 10),
150+
PageRequest.of(0, 10), null,
146151
loggedInUser);
147152

148153
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -151,6 +156,7 @@ void shouldListWithActiveFalse() {
151156
.isEqualTo(person.getPersonName());
152157
verify(personService).list(
153158
any(Pageable.class),
159+
isNull(),
154160
eq(loggedInUser),
155161
eq(false));
156162
verifyNoMoreInteractions(personService);
@@ -170,13 +176,15 @@ void shouldApplyCustomPaginationAndSorting() {
170176

171177
when(personService.list(
172178
eq(customPageable),
179+
isNull(),
173180
any(),
174-
any()))
181+
isNull()))
175182
.thenReturn(page);
176183

177184
ResponseEntity<CustomPage<PersonListingData>> response = personController.list(
178185
null,
179186
customPageable,
187+
null,
180188
loggedInUser);
181189

182190
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
@@ -186,8 +194,9 @@ void shouldApplyCustomPaginationAndSorting() {
186194

187195
verify(personService).list(
188196
eq(customPageable),
197+
isNull(),
189198
any(),
190-
any());
199+
isNull());
191200
}
192201
}
193202

@@ -200,6 +209,7 @@ void shouldThrowExceptionWhenLoggedInUserIsNull() {
200209
PageRequest.of(
201210
0,
202211
10),
212+
null,
203213
null))
204214
.isInstanceOf(NullPointerException.class);
205215
}
@@ -208,20 +218,23 @@ void shouldThrowExceptionWhenLoggedInUserIsNull() {
208218
void shouldReturnInternalServerErrorWhenServiceThrows() {
209219
when(personService.list(
210220
any(Pageable.class),
221+
isNull(),
211222
any(User.class),
212-
any()))
223+
isNull()))
213224
.thenThrow(new RuntimeException("Service error"));
214225

215226
assertThatThrownBy(() -> personController.list(
216227
null, PageRequest.of(
217228
0,
218229
10),
230+
null,
219231
loggedInUser))
220232
.isInstanceOf(RuntimeException.class)
221233
.hasMessageContaining("Service error");
222234

223235
verify(personService).list(
224236
any(Pageable.class),
237+
isNull(),
225238
eq(loggedInUser),
226239
isNull());
227240
}
@@ -230,13 +243,14 @@ void shouldReturnInternalServerErrorWhenServiceThrows() {
230243
void shouldReturnEmptyPageWhenNoPersonsFound() {
231244
when(personService.list(
232245
any(Pageable.class),
246+
isNull(),
233247
any(User.class),
234-
any()))
248+
isNull()))
235249
.thenReturn(Page.empty());
236250

237251
ResponseEntity<CustomPage<PersonListingData>> response = personController.list(
238252
null,
239-
PageRequest.of(0, 10),
253+
PageRequest.of(0, 10), null,
240254
loggedInUser);
241255

242256
assertThat(response.getBody().getContent()).isEmpty();

src/test/java/com/github/renancvitor/inventory/service/person/PersonServiceListTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void shouldListAllPeople() {
7373
.thenReturn(page);
7474

7575
Page<PersonListingData> result = personService.list(
76-
PageRequest.of(0, 10),
76+
PageRequest.of(0, 10), null,
7777
loggedInUser, null);
7878

7979
assertEquals(1, result.getTotalElements());
@@ -90,7 +90,7 @@ void shouldFilterByActiveTrue() {
9090
.thenReturn(page);
9191

9292
Page<PersonListingData> result = personService.list(
93-
PageRequest.of(0, 10),
93+
PageRequest.of(0, 10), null,
9494
loggedInUser, true);
9595

9696
assertEquals(1, result.getTotalElements());
@@ -107,7 +107,7 @@ void shouldFilterByActiveFalse() {
107107
.thenReturn(page);
108108

109109
Page<PersonListingData> result = personService.list(
110-
PageRequest.of(0, 10),
110+
PageRequest.of(0, 10), null,
111111
loggedInUser, false);
112112

113113
assertEquals(1, result.getTotalElements());
@@ -126,7 +126,7 @@ void shouldIgnoreFiltersWhenAllAreNull() {
126126
.thenReturn(page);
127127

128128
Page<PersonListingData> result = personService.list(
129-
PageRequest.of(0, 10),
129+
PageRequest.of(0, 10), null,
130130
null, null);
131131

132132
assertNotNull(result);
@@ -147,7 +147,7 @@ void shouldFailWhenUserIsNotAuthorized() {
147147
.authorize(anyList());
148148

149149
assertThrows(AuthorizationException.class,
150-
() -> personService.list(PageRequest.of(0, 10), loggedInUser, null));
150+
() -> personService.list(PageRequest.of(0, 10), null, loggedInUser, null));
151151
}
152152
}
153153

0 commit comments

Comments
 (0)