Skip to content

Commit e985143

Browse files
test(pagination): fix linting issues(3)
1 parent be69a5b commit e985143

5 files changed

Lines changed: 36 additions & 25 deletions

File tree

src/test/java/apimatic/core/EndToEndTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,20 @@ public class EndToEndTest extends MockCoreConfig {
129129
* Subclasses can override this method to provide a custom response retrieval mechanism.
130130
* If overridden, ensure thread-safety and proper response management.
131131
*/
132+
133+
/**
134+
* Returns the current Response object.
135+
*
136+
* @return the response instance
137+
*/
132138
protected Response getResponse() {
133139
return response;
134140
}
135141

136142
/**
137143
* Allows subclasses to customize how the response is set.
138144
* <p>
139-
* If overridden, ensure that the response is correctly handled and does not introduce memory leaks.
145+
* Ensure that the response is correctly handled and does not introduce memory leaks.
140146
*
141147
* @param response The response to set.
142148
*/

src/test/java/apimatic/core/RequestBuilderTest.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ public void testUpdateSimpleFormParam() throws IOException {
174174
public void testUpdateComplexFormParam() throws IOException {
175175
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
176176
.formParam(param -> param.key("form")
177-
.value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
177+
.value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
178178

179179
updateAndVerify(localRequestBuilder, "$request.body#/form/NumberOfElectrons",
180-
ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
180+
ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
181181
}
182182

183183
@Test
@@ -192,28 +192,29 @@ public void testUpdateSimpleQueryParam() throws IOException {
192192
public void testUpdateComplexQueryParam() throws IOException {
193193
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
194194
.queryParam(param -> param.key("que")
195-
.value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
195+
.value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
196196

197197
updateAndVerify(localRequestBuilder, "$request.query#/que/NumberOfElectrons",
198-
ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
198+
ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
199199
}
200200

201201
@Test
202202
public void testUpdateSimpleHeaderParam() throws IOException {
203203
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
204204
.headerParam(param -> param.key("head").value(HEADER_DEFAULT));
205205

206-
updateAndVerify(localRequestBuilder, "$request.headers#/head", HEADER_DEFAULT, HEADER_UPDATED);
206+
updateAndVerify(localRequestBuilder, "$request.headers#/head",
207+
HEADER_DEFAULT, HEADER_UPDATED);
207208
}
208209

209210
@Test
210211
public void testUpdateComplexHeaderParam() throws IOException {
211212
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
212213
.headerParam(param -> param.key("head")
213-
.value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
214+
.value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
214215

215216
updateAndVerify(localRequestBuilder, "$request.headers#/head/NumberOfElectrons",
216-
ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
217+
ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
217218
}
218219

219220
@Test
@@ -231,19 +232,19 @@ public void testUpdateComplexBodyParam() throws IOException {
231232
.bodyParam(param -> param.value(new Atom(ATOM_NUMBER, ATOM_MASS)));
232233

233234
updateAndVerify(localRequestBuilder, "$request.body#/NumberOfElectrons",
234-
ATOM_NUMBER, ATOM_MASS);
235+
ATOM_NUMBER, ATOM_MASS);
235236
}
236237

237238
@Test
238239
public void testUpdateMultipleComplexBodyParams() throws IOException {
239240
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.POST)
240241
.bodyParam(param -> param.key("bodyA")
241-
.value(new Atom(BODY_A_ELECTRONS, BODY_A_MASS)))
242+
.value(new Atom(BODY_A_ELECTRONS, BODY_A_MASS)))
242243
.bodyParam(param -> param.key("bodyB")
243-
.value(new Atom(BODY_B_ELECTRONS, BODY_B_MASS)));
244+
.value(new Atom(BODY_B_ELECTRONS, BODY_B_MASS)));
244245

245246
updateAndVerify(localRequestBuilder, "$request.body#/bodyB/NumberOfElectrons",
246-
BODY_B_ELECTRONS, BODY_B_UPDATED);
247+
BODY_B_ELECTRONS, BODY_B_UPDATED);
247248
}
248249

249250
@Test
@@ -255,7 +256,7 @@ public void testUpdateSimpleBodyParam() throws IOException {
255256
}
256257

257258
private void updateAndVerify(HttpRequest.Builder requestBuilder,
258-
String pointer, Object oldValue, Object newValue) {
259+
String pointer, Object oldValue, Object newValue) {
259260
requestBuilder.updateParameterByJsonPointer(pointer, old -> {
260261
assertEquals(oldValue.toString(), old.toString());
261262
return newValue;
@@ -273,8 +274,8 @@ private void updateAndVerify(HttpRequest.Builder requestBuilder,
273274
public void testBodyParamValidation() throws IOException {
274275
// when
275276
new HttpRequest.Builder()
276-
.httpMethod(Method.POST)
277-
.bodyParam(param -> param.value(null))
277+
.httpMethod(Method.POST)
278+
.bodyParam(param -> param.value(null))
278279
.build(getMockGlobalConfig());
279280
}
280281

src/test/java/apimatic/core/type/pagination/CursorPaginationTest.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
public class CursorPaginationTest {
2222

23+
/**
24+
* Initializes Mockito rule to enable Mockito annotations and
25+
* silently handle unnecessary stubbings during tests.
26+
*/
2327
@Rule
2428
public MockitoRule initRule = MockitoJUnit.rule().silent();
2529

@@ -43,7 +47,7 @@ public void testWithValidCursor() {
4347
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_STRING);
4448

4549
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_VALID,
46-
REQUEST_QUERY_POINTER);
50+
REQUEST_QUERY_POINTER);
4751

4852
Builder requestBuilder = cursor.apply(paginatedData);
4953
assertNotNull(requestBuilder);
@@ -67,7 +71,7 @@ public void testWithValidCursorAndDifferentTypeA() {
6771
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_INT);
6872

6973
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_VALID,
70-
REQUEST_QUERY_POINTER);
74+
REQUEST_QUERY_POINTER);
7175

7276
Builder requestBuilder = cursor.apply(paginatedData);
7377
assertNotNull(requestBuilder);
@@ -92,7 +96,7 @@ public void testWithValidCursorAndDifferentType() {
9296
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_INT);
9397

9498
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_VALID,
95-
REQUEST_QUERY_POINTER);
99+
REQUEST_QUERY_POINTER);
96100

97101
Builder requestBuilder = cursor.apply(paginatedData);
98102
assertNotNull(requestBuilder);
@@ -115,7 +119,7 @@ public void testWithValidCursorButMissingInFirstRequest() {
115119
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_STRING);
116120

117121
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_VALID,
118-
REQUEST_QUERY_POINTER);
122+
REQUEST_QUERY_POINTER);
119123

120124
Builder requestBuilder = cursor.apply(paginatedData);
121125
assertNull(requestBuilder);
@@ -132,7 +136,7 @@ public void testWithValidCursorFromResponseBody() {
132136
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_INT);
133137

134138
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_VALID,
135-
REQUEST_QUERY_POINTER);
139+
REQUEST_QUERY_POINTER);
136140

137141
Builder requestBuilder = cursor.apply(paginatedData);
138142
assertNotNull(requestBuilder);
@@ -156,7 +160,7 @@ public void testWithInvalidResponsePointer() {
156160
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_STRING);
157161

158162
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_INVALID,
159-
REQUEST_HEADER_POINTER);
163+
REQUEST_HEADER_POINTER);
160164

161165
Builder requestBuilder = cursor.apply(paginatedData);
162166
assertNull(requestBuilder);
@@ -189,7 +193,7 @@ public void testWithInvalidRequestPointer() {
189193
when(response.getBody()).thenReturn(NEXT_CURSOR_JSON_STRING);
190194

191195
CursorPagination cursor = new CursorPagination(RESPONSE_POINTER_VALID,
192-
REQUEST_POINTER_INVALID);
196+
REQUEST_POINTER_INVALID);
193197

194198
assertNull(cursor.apply(paginatedData));
195199
}

src/test/java/apimatic/core/type/pagination/PagePaginationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ public void testWithInvalidStringPage() {
174174

175175
when(paginatedData.getRequestBuilder())
176176
.thenReturn(new HttpRequest.Builder()
177-
.queryParam(q -> q.key("page")
178-
.value(INVALID_PAGE_STRING)));
177+
.queryParam(q -> q.key("page")
178+
.value(INVALID_PAGE_STRING)));
179179
when(paginatedData.getResponse()).thenReturn(response);
180180
when(response.getBody()).thenReturn("{\"page\": \"" + INVALID_PAGE_STRING + "\"}");
181181

src/test/java/apimatic/core/type/pagination/PaginatedDataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public void testInvalidPaginationWithFailingResponse() throws IOException {
7474
public void testInvalidPaginationWithFailingResponseAsync()
7575
throws IOException, InterruptedException, ExecutionException {
7676
Runnable call1 = () -> when(getResponse()
77-
.getStatusCode()).thenReturn(NOT_FOUND_STATUS_CODE);
77+
.getStatusCode()).thenReturn(NOT_FOUND_STATUS_CODE);
7878
PaginatedData<String, PageWrapper<String, RecordPage>,
7979
RecordPage, CoreApiException> paginatedData = getPaginatedData(call1, null, null,
8080
new LinkPagination("$response.body#/next_link"));

0 commit comments

Comments
 (0)