Skip to content

Commit 44921ae

Browse files
committed
http202 remove reflection from unit tests
Signed-off-by: davidradl <[email protected]>
1 parent 1c27190 commit 44921ae

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/main/java/com/getindata/connectors/http/internal/table/lookup/JavaNetHttpPollingClient.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ private Collection<RowData> deserialize(String responseBody) throws IOException
269269
}
270270
}
271271

272-
private List<RowData> deserializeSingleValue(byte[] rawBytes) throws IOException {
272+
@VisibleForTesting
273+
List<RowData> deserializeSingleValue(byte[] rawBytes) throws IOException {
273274
List<RowData> result = new ArrayList<>();
274275
responseBodyDecoder.deserialize(rawBytes, createRowDataCollector(result));
275276
return result;
@@ -302,7 +303,8 @@ public void close() {
302303
}
303304
}
304305

305-
private List<RowData> deserializeArray(byte[] rawBytes) throws IOException {
306+
@VisibleForTesting
307+
List<RowData> deserializeArray(byte[] rawBytes) throws IOException {
306308
List<JsonNode> rawObjects =
307309
objectMapper.readValue(rawBytes, new TypeReference<>() {
308310
});

src/test/java/com/getindata/connectors/http/internal/table/lookup/JavaNetHttpPollingClientTest.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,8 @@ public org.apache.flink.api.common.typeinfo.TypeInformation<RowData> getProduced
357357
);
358358

359359
// WHEN
360-
java.lang.reflect.Method method = JavaNetHttpPollingClient.class
361-
.getDeclaredMethod("deserializeArray", byte[].class);
362-
method.setAccessible(true);
363-
364360
String jsonArray = "[{\"key\":\"value1\"},{\"key\":\"value2\"}]";
365-
List<RowData> result = (List<RowData>) method.invoke(client, jsonArray.getBytes());
361+
List<RowData> result = client.deserializeArray(jsonArray.getBytes());
366362

367363
// THEN
368364
assertThat(result).isNotNull();
@@ -415,12 +411,8 @@ public org.apache.flink.api.common.typeinfo.TypeInformation<RowData> getProduced
415411
);
416412

417413
// WHEN
418-
java.lang.reflect.Method method = JavaNetHttpPollingClient.class
419-
.getDeclaredMethod("deserializeArray", byte[].class);
420-
method.setAccessible(true);
421-
422414
String jsonArray = "[{\"key\":\"value1\"},null,{\"key\":\"value2\"}]";
423-
List<RowData> result = (List<RowData>) method.invoke(client, jsonArray.getBytes());
415+
List<RowData> result = client.deserializeArray(jsonArray.getBytes());
424416

425417
// THEN - null nodes should be skipped
426418
assertThat(result).isNotNull();
@@ -478,12 +470,8 @@ public org.apache.flink.api.common.typeinfo.TypeInformation<RowData> getProduced
478470
);
479471

480472
// WHEN
481-
java.lang.reflect.Method method = JavaNetHttpPollingClient.class
482-
.getDeclaredMethod("deserializeArray", byte[].class);
483-
method.setAccessible(true);
484-
485473
String jsonArray = "[{\"status\":\"invalid\"},{\"status\":\"valid\"},{\"status\":\"invalid\"}]";
486-
List<RowData> result = (List<RowData>) method.invoke(client, jsonArray.getBytes());
474+
List<RowData> result = client.deserializeArray(jsonArray.getBytes());
487475

488476
// THEN - only valid deserialization should be included
489477
assertThat(result).isNotNull();

0 commit comments

Comments
 (0)