Skip to content

Commit e39684d

Browse files
committed
fixes sonar cube issues
1 parent b6f45db commit e39684d

7 files changed

Lines changed: 42 additions & 46 deletions

File tree

src/main/java/io/apimatic/core/ApiCall.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public ResponseType execute() throws IOException, ExceptionType {
105105
Context context = globalConfig.getCompatibilityFactory()
106106
.createHttpContext(request, response);
107107

108-
return responseHandler.handle(context, endpointConfiguration, globalConfig, requestBuilder);
108+
return responseHandler.handle(context, endpointConfiguration, globalConfig);
109109
}
110110

111111
/**
@@ -116,12 +116,11 @@ public CompletableFuture<ResponseType> executeAsync() {
116116
return AsyncExecutor.makeHttpCallAsync(() -> requestBuilder.build(globalConfig),
117117
request -> globalConfig.getHttpClient()
118118
.executeAsync(request, endpointConfiguration),
119-
(request, response) -> {
120-
this.response = response;
119+
(req, res) -> {
120+
this.response = res;
121121
Context context = globalConfig.getCompatibilityFactory()
122-
.createHttpContext(request, response);
123-
return responseHandler.handle(context, endpointConfiguration, globalConfig,
124-
requestBuilder);
122+
.createHttpContext(req, res);
123+
return responseHandler.handle(context, endpointConfiguration, globalConfig);
125124
}, apiLogger);
126125
}
127126

src/main/java/io/apimatic/core/HttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ private void updateBodyParams(UnaryOperator<Object> setter, String point) {
364364
return;
365365
}
366366

367-
if (bodySerializer != null && point == "") {
367+
if (bodySerializer != null && "".equals(point)) {
368368
try {
369369
String serializedBody = bodySerializer.supply();
370370
String newSerializedBody = setter.apply(serializedBody).toString();
@@ -375,7 +375,7 @@ private void updateBodyParams(UnaryOperator<Object> setter, String point) {
375375
return;
376376
}
377377

378-
if ((body instanceof String && point == "") || point == "") {
378+
if ((body instanceof String && "".equals(point)) || "".equals(point)) {
379379
body = setter.apply(body);
380380
return;
381381
}

src/main/java/io/apimatic/core/ResponseHandler.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,14 @@ private ResponseHandler(final Map<String, ErrorCase<ExceptionType>> localErrorCa
114114
* @param context Context which is made for endpoint.
115115
* @param config All endPoint level configuration.
116116
* @param globalConfig All apiCall level configuration.
117-
* @param requestBuilder The requestBuilder that can re create current API Call.
118117
*
119118
* @return An object of type ResponseType.
120119
* @throws IOException Signals that an I/O exception of some sort has
121120
* occurred.
122121
* @throws ExceptionType Represents error response from the server.
123122
*/
124123
public ResponseType handle(Context context, EndpointConfiguration config,
125-
GlobalConfiguration globalConfig, HttpRequest.Builder requestBuilder)
126-
throws IOException, ExceptionType {
124+
GlobalConfiguration globalConfig) throws IOException, ExceptionType {
127125
if (globalConfig.getHttpCallback() != null) {
128126
// invoke the callback after response if its not null
129127
globalConfig.getHttpCallback().onAfterResponse(context);
@@ -140,8 +138,7 @@ public ResponseType handle(Context context, EndpointConfiguration config,
140138
// handle errors defined at the API level
141139
validateResponse(context);
142140

143-
Object result = convertResponse(context.getResponse(), requestBuilder, config,
144-
globalConfig);
141+
Object result = convertResponse(context.getResponse(), config, globalConfig);
145142

146143
if (responseClassType == ResponseClassType.API_RESPONSE
147144
|| responseClassType == ResponseClassType.DYNAMIC_API_RESPONSE) {
@@ -161,8 +158,8 @@ private ResponseType applyContextInitializer(Context httpContext,
161158
return (ResponseType) result;
162159
}
163160

164-
private Object convertResponse(Response response, HttpRequest.Builder requestBuilder,
165-
EndpointConfiguration config, GlobalConfiguration globalConfig) throws IOException {
161+
private Object convertResponse(Response response, EndpointConfiguration config,
162+
GlobalConfiguration globalConfig) throws IOException {
166163
if (responseClassType == ResponseClassType.DYNAMIC_RESPONSE
167164
|| responseClassType == ResponseClassType.DYNAMIC_API_RESPONSE) {
168165
return createDynamicResponse(response, globalConfig.getCompatibilityFactory());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import io.apimatic.core.types.CoreApiException;
66

7-
public interface CheckedSupplier<T, ExceptionType extends CoreApiException> {
7+
public interface CheckedSupplier<T, E extends CoreApiException> {
88

99
@SuppressWarnings("unchecked")
10-
public static <T, E extends CoreApiException> CheckedSupplier<T, E> CreateError(
10+
public static <T, E extends CoreApiException> CheckedSupplier<T, E> createError(
1111
Throwable exception) {
1212
if (exception instanceof IOException) {
1313
return new CheckedSupplier<T, E>()
@@ -33,7 +33,7 @@ public T get() throws E, IOException {
3333

3434
}
3535

36-
public static <T, E extends CoreApiException> CheckedSupplier<T, E> Create(T item) {
36+
public static <T, E extends CoreApiException> CheckedSupplier<T, E> create(T item) {
3737
return new CheckedSupplier<T, E>()
3838
{
3939
@Override
@@ -43,5 +43,5 @@ public T get() throws E, IOException {
4343
};
4444
}
4545

46-
T get() throws ExceptionType, IOException;
46+
T get() throws E, IOException;
4747
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ private boolean updateWith(ApiCall<Res, ExceptionType> apiCall, Res pageUnWrappe
209209
this.apiCall = apiCall;
210210
PageWrapper<I, Res> pageWrapper = PageWrapper.Create(apiCall.getResponse(), pageUnWrapped, itemsUnWrapped);
211211
strategy.addMetaData(pageWrapper);
212-
this.page = CheckedSupplier.Create(pageCreator.apply(pageWrapper));
213-
itemsUnWrapped.forEach(i -> items.add(CheckedSupplier.Create(i)));
212+
this.page = CheckedSupplier.create(pageCreator.apply(pageWrapper));
213+
itemsUnWrapped.forEach(i -> items.add(CheckedSupplier.create(i)));
214214

215215
if (canLockStrategy) {
216216
lockedStrategy = strategy;
@@ -222,10 +222,10 @@ private boolean updateWith(ApiCall<Res, ExceptionType> apiCall, Res pageUnWrappe
222222
}
223223

224224
private boolean updateAsFailed(Throwable exp) {
225-
page = CheckedSupplier.CreateError(exp);
225+
page = CheckedSupplier.createError(exp);
226226
itemIndex = 0;
227227
items.clear();
228-
items.add(CheckedSupplier.CreateError(exp));
228+
items.add(CheckedSupplier.createError(exp));
229229
dataClosed = true;
230230

231231
return true;

src/test/java/apimatic/core/ResponseHandlerTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void testDeserializerMethod() throws IOException, CoreApiException {
177177

178178
// verify
179179
assertEquals(coreResponseHandler.handle(context, endpointSetting,
180-
getMockGlobalConfig(), requestBuilder), "bodyValue");
180+
getMockGlobalConfig()), "bodyValue");
181181
}
182182

183183
@Test
@@ -195,7 +195,7 @@ public void testDeserializerMethodUsingRawBody() throws IOException, CoreApiExce
195195

196196
// verify
197197
assertEquals(coreResponseHandler.handle(context, endpointSetting,
198-
getMockGlobalConfig(), requestBuilder), inputStream);
198+
getMockGlobalConfig()), inputStream);
199199
}
200200

201201

@@ -215,7 +215,7 @@ public void testDeserializerMethodUsingContext() throws IOException, CoreApiExce
215215

216216
// verify
217217
assertEquals(coreResponseHandler.handle(context, endpointSetting,
218-
getMockGlobalConfig(), requestBuilder).getContext(), model.getContext());
218+
getMockGlobalConfig()).getContext(), model.getContext());
219219
}
220220

221221
@Test
@@ -230,7 +230,7 @@ public void testContextWithoutDeserializer() throws IOException, CoreApiExceptio
230230

231231
// verify
232232
assertNull(coreResponseHandler.handle(context, endpointSetting,
233-
getMockGlobalConfig(), requestBuilder));
233+
getMockGlobalConfig()));
234234
}
235235

236236
@Test
@@ -245,7 +245,7 @@ public void testDynamicResponseTypeMethod() throws IOException, CoreApiException
245245

246246
// verify
247247
assertEquals(coreResponseHandler.handle(context, endpointSetting,
248-
getMockGlobalConfig(), requestBuilder), dynamicType);
248+
getMockGlobalConfig()), dynamicType);
249249
}
250250

251251
@Test
@@ -263,7 +263,7 @@ public void testApiResponseTypeMethod() throws IOException, CoreApiException {
263263
// verify
264264
assertEquals(
265265
coreResponseHandler.handle(context, endpointSetting,
266-
getMockGlobalConfig(), requestBuilder).getResult(),
266+
getMockGlobalConfig()).getResult(),
267267
stringApiResponseType.getResult());
268268
}
269269

@@ -280,7 +280,7 @@ public void testDynamicApiResponseTypeMethod() throws IOException, CoreApiExcept
280280
// verify
281281
assertEquals(
282282
coreResponseHandler.handle(context, endpointSetting,
283-
getMockGlobalConfig(), requestBuilder).getResult(),
283+
getMockGlobalConfig()).getResult(),
284284
dynamicApiResponseType.getResult());
285285
}
286286

@@ -292,7 +292,7 @@ public void testDefaultTypeMethod() throws IOException, CoreApiException {
292292
when(coreHttpResponse.getStatusCode()).thenReturn(CREATED_SUCCESS_CODE);
293293
// verify
294294
assertNull(coreResponseHandler.handle(context, endpointSetting,
295-
getMockGlobalConfig(), requestBuilder));
295+
getMockGlobalConfig()));
296296
}
297297

298298
@Test
@@ -307,7 +307,7 @@ public void testNullify404() throws IOException, CoreApiException {
307307

308308
// verify
309309
assertNull(coreResponseHandler.handle(context, endpointSetting,
310-
getMockGlobalConfig(), requestBuilder));
310+
getMockGlobalConfig()));
311311
}
312312

313313
@Test
@@ -320,7 +320,7 @@ public void testNullify404False() throws IOException, CoreApiException {
320320

321321
CoreApiException apiException = assertThrows(CoreApiException.class, () -> {
322322
coreResponseHandler.handle(context, endpointSetting,
323-
getMockGlobalConfig(), requestBuilder);
323+
getMockGlobalConfig());
324324
});
325325

326326
String expectedMessage = "Not found";
@@ -342,19 +342,19 @@ public void testNullableResponseType() throws IOException, CoreApiException {
342342

343343
// verify
344344
assertNull(coreResponseHandler.handle(context, endpointSetting,
345-
getMockGlobalConfig(), requestBuilder));
345+
getMockGlobalConfig()));
346346

347347
when(coreHttpResponse.getBody()).thenReturn("");
348348

349349
// verify
350350
assertNull(coreResponseHandler.handle(context, endpointSetting,
351-
getMockGlobalConfig(), requestBuilder));
351+
getMockGlobalConfig()));
352352

353353
when(coreHttpResponse.getBody()).thenReturn(" ");
354354

355355
// verify
356356
assertNull(coreResponseHandler.handle(context, endpointSetting,
357-
getMockGlobalConfig(), requestBuilder));
357+
getMockGlobalConfig()));
358358
}
359359

360360
@Test
@@ -370,20 +370,20 @@ public void testNullableResponseTypeFalse() throws IOException, CoreApiException
370370

371371
// verify
372372
assertEquals(Integer.valueOf(body), coreResponseHandler.handle(context, endpointSetting,
373-
getMockGlobalConfig(), requestBuilder));
373+
getMockGlobalConfig()));
374374

375375
when(coreHttpResponse.getBody()).thenReturn("");
376376

377377
assertThrows(NumberFormatException.class, () -> {
378378
coreResponseHandler.handle(context, endpointSetting,
379-
getMockGlobalConfig(), requestBuilder);
379+
getMockGlobalConfig());
380380
});
381381

382382
when(coreHttpResponse.getBody()).thenReturn(" ");
383383

384384
assertThrows(NumberFormatException.class, () -> {
385385
coreResponseHandler.handle(context, endpointSetting,
386-
getMockGlobalConfig(), requestBuilder);
386+
getMockGlobalConfig());
387387
});
388388
}
389389

@@ -400,7 +400,7 @@ public void testLocalException() throws IOException, CoreApiException {
400400

401401
CoreApiException apiException = assertThrows(CoreApiException.class, () -> {
402402
coreResponseHandler.handle(context, endpointSetting,
403-
getMockGlobalConfig(), requestBuilder);
403+
getMockGlobalConfig());
404404
});
405405

406406
String expectedMessage = "Forbidden";
@@ -423,7 +423,7 @@ public void testDefaultException() throws IOException, CoreApiException {
423423

424424
CoreApiException apiException = assertThrows(CoreApiException.class, () -> {
425425
coreResponseHandler.handle(context, endpointSetting,
426-
getMockGlobalConfig(), requestBuilder);
426+
getMockGlobalConfig());
427427
});
428428

429429
String expectedMessage = "Invalid response.";
@@ -449,7 +449,7 @@ public void testDefaultException1() throws IOException, CoreApiException {
449449

450450
CoreApiException apiException = assertThrows(CoreApiException.class, () -> {
451451
coreResponseHandler.handle(context, endpointSetting,
452-
getMockGlobalConfig(), requestBuilder);
452+
getMockGlobalConfig());
453453
});
454454

455455
String expectedMessage = "Invalid response.";
@@ -485,7 +485,7 @@ public void testGlobalException() throws IOException, CoreApiException {
485485

486486
GlobalTestException apiException = assertThrows(GlobalTestException.class, () -> {
487487
coreResponseHandler.handle(context, endpointSetting,
488-
getMockGlobalConfig(), requestBuilder);
488+
getMockGlobalConfig());
489489
});
490490

491491
String expectedMessage = "Bad Request";

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@ 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 = CheckedSupplier.createError(ioException);
1717
@SuppressWarnings("unused")
1818
String value = supplier.get();
1919
}
2020

2121
@Test(expected = CoreApiException.class)
2222
public void testCreateErrorWithCoreApiException() throws Exception {
2323
CoreApiException apiException = new CoreApiException("Test API Exception");
24-
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.CreateError(apiException);
24+
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.createError(apiException);
2525
@SuppressWarnings("unused")
2626
String value = supplier.get();
2727
}
2828

2929
@Test
3030
public void testCreateErrorWithUnsupportedException() {
3131
RuntimeException runtimeException = new RuntimeException("Test Exception");
32-
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.CreateError(runtimeException);
32+
CheckedSupplier<String, CoreApiException> supplier = CheckedSupplier.createError(runtimeException);
3333
assertNull(supplier);
3434
}
3535
}

0 commit comments

Comments
 (0)