Skip to content

Commit 4bf5576

Browse files
test(pagination): fix linting issues
1 parent 319ba7e commit 4bf5576

11 files changed

Lines changed: 177 additions & 172 deletions

File tree

src/main/java/io/apimatic/core/types/pagination/PaginatedData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ public PaginatedData<I, P, R, E> copy() {
165165
}
166166

167167
/**
168-
* Start fetching the next page asynchronously.
169-
* @return A CompletableFuture of boolean instance suggesting if there is a next page or not.
168+
* Start fetching the next page asynchronously.
169+
* @return A CompletableFuture of boolean instance suggesting if there is a next page or not.
170170
*/
171171
public CompletableFuture<Boolean> fetchNextPageAsync() {
172172
if (dataClosed) {

src/main/java/io/apimatic/core/utilities/CoreHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ private static JsonValue toJsonValue(Object obj) {
17791779
return Json.createValue((Double) obj);
17801780
}
17811781
if (obj instanceof Boolean) {
1782-
return Boolean.TRUE.equals(obj) ? JsonValue.TRUE : JsonValue.FALSE; // ✅ Safe & compliant
1782+
return Boolean.TRUE.equals(obj) ? JsonValue.TRUE : JsonValue.FALSE;
17831783
}
17841784
return null;
17851785
}

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,14 @@ public class EndToEndTest extends MockCoreConfig {
122122
* Mock of {@link Response}.
123123
*/
124124
@Mock
125-
protected Response response;
125+
private Response response;
126+
protected Response getResponse() {
127+
return response;
128+
}
126129

130+
protected void setResponse(Response response) {
131+
this.response = response;
132+
}
127133

128134
/**
129135
* Mock of {@link Request}.
@@ -500,7 +506,16 @@ private ApiCall<String, CoreApiException> getApiCallGlobalErrorTemplateWithHeade
500506
.hasBinaryResponse(false).retryOption(RetryOption.DEFAULT))
501507
.build();
502508
}
503-
509+
510+
/**
511+
* Creates a global configuration instance with the provided callback.
512+
* This method is designed for extension by subclasses to customize global configuration.
513+
* Subclasses should override this method and call super.getGlobalConfig(callback)
514+
* to maintain base functionality while adding custom configurations.
515+
*
516+
* @param callback The callback instance to use in the configuration
517+
* @return A fully configured GlobalConfiguration instance
518+
*/
504519
protected GlobalConfiguration getGlobalConfig(Callback callback) {
505520
String userAgent = "APIMATIC 3.0";
506521
GlobalConfiguration globalConfig = new GlobalConfiguration.Builder()

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

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@
6060

6161
public class RequestBuilderTest extends MockCoreConfig {
6262

63+
private static final int ELECTRONS_DEFAULT = 12;
64+
private static final int ELECTRONS_UPDATED = 14;
65+
private static final long QUERY_DEFAULT = 234L;
66+
private static final long QUERY_UPDATED = 254L;
67+
private static final double HEADER_DEFAULT = 2.14;
68+
private static final double HEADER_UPDATED = 19.95;
69+
private static final int ATOM_NUMBER = 23;
70+
private static final int ATOM_MASS = 24;
71+
private static final int BODY_A_ELECTRONS = 2;
72+
private static final int BODY_A_MASS = 4;
73+
private static final int BODY_B_ELECTRONS = 4;
74+
private static final int BODY_B_MASS = 2;
75+
private static final int BODY_B_UPDATED = 8;
76+
77+
6378
/**
6479
* Initializes mocks annotated with Mock.
6580
*/
@@ -142,7 +157,7 @@ public void testUpdatePathParam() throws IOException {
142157
public void testUpdatePathParamArray() throws IOException {
143158
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
144159
.templateParam(param -> param.key("temp")
145-
.value(new String[] { "apple", "banana", "cherry" }));
160+
.value(new String[] {"apple", "banana", "cherry" }));
146161

147162
updateAndVerify(localRequestBuilder, "$request.path#/temp/1", "banana", "mango");
148163
}
@@ -158,41 +173,41 @@ public void testUpdateSimpleFormParam() throws IOException {
158173
@Test
159174
public void testUpdateComplexFormParam() throws IOException {
160175
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
161-
.formParam(param -> param.key("form").value(new Atom(12, 12)));
176+
.formParam(param -> param.key("form").value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
162177

163-
updateAndVerify(localRequestBuilder, "$request.body#/form/NumberOfElectrons", 12, 14);
178+
updateAndVerify(localRequestBuilder, "$request.body#/form/NumberOfElectrons", ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
164179
}
165180

166181
@Test
167182
public void testUpdateSimpleQueryParam() throws IOException {
168183
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
169-
.queryParam(param -> param.key("que").value(234L));
184+
.queryParam(param -> param.key("que").value(QUERY_DEFAULT));
170185

171-
updateAndVerify(localRequestBuilder, "$request.query#/que", 234L, 254L);
186+
updateAndVerify(localRequestBuilder, "$request.query#/que", QUERY_DEFAULT, QUERY_UPDATED);
172187
}
173188

174189
@Test
175190
public void testUpdateComplexQueryParam() throws IOException {
176191
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
177-
.queryParam(param -> param.key("que").value(new Atom(12, 12)));
192+
.queryParam(param -> param.key("que").value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
178193

179-
updateAndVerify(localRequestBuilder, "$request.query#/que/NumberOfElectrons", 12, 14);
194+
updateAndVerify(localRequestBuilder, "$request.query#/que/NumberOfElectrons", ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
180195
}
181196

182197
@Test
183198
public void testUpdateSimpleHeaderParam() throws IOException {
184199
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
185-
.headerParam(param -> param.key("head").value(2.14));
200+
.headerParam(param -> param.key("head").value(HEADER_DEFAULT));
186201

187-
updateAndVerify(localRequestBuilder, "$request.headers#/head", 2.14, 19.95);
202+
updateAndVerify(localRequestBuilder, "$request.headers#/head", HEADER_DEFAULT, HEADER_UPDATED);
188203
}
189204

190205
@Test
191206
public void testUpdateComplexHeaderParam() throws IOException {
192207
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.GET)
193-
.headerParam(param -> param.key("head").value(new Atom(12, 12)));
208+
.headerParam(param -> param.key("head").value(new Atom(ELECTRONS_DEFAULT, ELECTRONS_DEFAULT)));
194209

195-
updateAndVerify(localRequestBuilder, "$request.headers#/head/NumberOfElectrons", 12, 14);
210+
updateAndVerify(localRequestBuilder, "$request.headers#/head/NumberOfElectrons", ELECTRONS_DEFAULT, ELECTRONS_UPDATED);
196211
}
197212

198213
@Test
@@ -207,18 +222,18 @@ public void testUpdateMultipleBodyParams() throws IOException {
207222
@Test
208223
public void testUpdateComplexBodyParam() throws IOException {
209224
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.POST)
210-
.bodyParam(param -> param.value(new Atom(23, 24)));
225+
.bodyParam(param -> param.value(new Atom(ATOM_NUMBER, ATOM_MASS)));
211226

212-
updateAndVerify(localRequestBuilder, "$request.body#/NumberOfElectrons", 23, 24);
227+
updateAndVerify(localRequestBuilder, "$request.body#/NumberOfElectrons", ATOM_NUMBER, ATOM_MASS);
213228
}
214229

215230
@Test
216231
public void testUpdateMultipleComplexBodyParams() throws IOException {
217232
HttpRequest.Builder localRequestBuilder = new HttpRequest.Builder().httpMethod(Method.POST)
218-
.bodyParam(param -> param.key("bodyA").value(new Atom(2, 4)))
219-
.bodyParam(param -> param.key("bodyB").value(new Atom(4, 2)));
233+
.bodyParam(param -> param.key("bodyA").value(new Atom(BODY_A_ELECTRONS, BODY_A_MASS)))
234+
.bodyParam(param -> param.key("bodyB").value(new Atom(BODY_B_ELECTRONS, BODY_B_MASS)));
220235

221-
updateAndVerify(localRequestBuilder, "$request.body#/bodyB/NumberOfElectrons", 4, 8);
236+
updateAndVerify(localRequestBuilder, "$request.body#/bodyB/NumberOfElectrons", BODY_B_ELECTRONS, BODY_B_UPDATED);
222237
}
223238

224239
@Test
@@ -230,14 +245,12 @@ public void testUpdateSimpleBodyParam() throws IOException {
230245
}
231246

232247
private void updateAndVerify(HttpRequest.Builder requestBuilder, String pointer, Object oldValue, Object newValue) {
233-
requestBuilder.updateParameterByJsonPointer(pointer, old ->
234-
{
248+
requestBuilder.updateParameterByJsonPointer(pointer, old -> {
235249
assertEquals(oldValue.toString(), old.toString());
236250
return newValue;
237251
});
238252
AtomicBoolean asserted = new AtomicBoolean(false);
239-
requestBuilder.updateParameterByJsonPointer(pointer, newV ->
240-
{
253+
requestBuilder.updateParameterByJsonPointer(pointer, newV -> {
241254
assertEquals(newValue.toString(), newV.toString());
242255
asserted.set(true);
243256
return newV;
@@ -248,25 +261,28 @@ private void updateAndVerify(HttpRequest.Builder requestBuilder, String pointer,
248261
@Test(expected = NullPointerException.class)
249262
public void testBodyParamValidation() throws IOException {
250263
// when
251-
new HttpRequest.Builder().httpMethod(Method.POST).bodyParam(param -> param.value(null))
264+
new HttpRequest.Builder()
265+
.httpMethod(Method.POST)
266+
.bodyParam(param -> param.value(null))
252267
.build(getMockGlobalConfig());
253-
254268
}
255269

256270
@Test(expected = NullPointerException.class)
257271
public void testBodyParamValidation1() throws IOException {
258272
// when
259-
new HttpRequest.Builder().httpMethod(Method.POST).bodyParam(param -> param.value(null))
273+
new HttpRequest.Builder()
274+
.httpMethod(Method.POST)
275+
.bodyParam(param -> param.value(null))
260276
.build(getMockGlobalConfig());
261-
262277
}
263278

264279
@Test
265280
public void testBodyParam() throws IOException {
266281
// when
267282
Request coreHttpRequest =
268283
new HttpRequest.Builder().httpMethod(Method.PATCH)
269-
.bodyParam(param -> param.value("bodyValue")).build(getMockGlobalConfig());
284+
.bodyParam(param -> param.value("bodyValue"))
285+
.build(getMockGlobalConfig());
270286

271287
when(coreHttpRequest.getBody()).thenReturn("bodyValue");
272288

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package apimatic.core.type.pagination;
22

3-
import static org.junit.Assert.*;
43
import org.junit.Test;
4+
import static org.junit.Assert.assertNull;
55

66
import java.io.IOException;
77

@@ -13,23 +13,26 @@ public class CheckedSupplierTest {
1313
@Test(expected = IOException.class)
1414
public void testCreateErrorWithIOException() throws Exception {
1515
IOException ioException = new IOException("Test IO Exception");
16-
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.createError(ioException);
16+
CheckedSupplier<String, CoreApiException> supplier =
17+
CheckedSupplier.createError(ioException);
1718
@SuppressWarnings("unused")
1819
String value = supplier.get();
1920
}
2021

2122
@Test(expected = CoreApiException.class)
2223
public void testCreateErrorWithCoreApiException() throws Exception {
2324
CoreApiException apiException = new CoreApiException("Test API Exception");
24-
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.createError(apiException);
25+
CheckedSupplier<String, CoreApiException> supplier =
26+
CheckedSupplier.createError(apiException);
2527
@SuppressWarnings("unused")
2628
String value = supplier.get();
2729
}
2830

2931
@Test
3032
public void testCreateErrorWithUnsupportedException() {
3133
RuntimeException runtimeException = new RuntimeException("Test Exception");
32-
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.createError(runtimeException);
34+
CheckedSupplier<String, CoreApiException> supplier =
35+
CheckedSupplier.createError(runtimeException);
3336
assertNull(supplier);
3437
}
3538
}

0 commit comments

Comments
 (0)