我如何对以下代码进行单元测试?
private Future<JSONArray> getData(String cqlQuery, String eventName) {
ExecutorService executor = Executors.newFixedThreadPool(1);
CqlClientCallable cqlClientCallable = new CqlClientCallable(cqlQuery,
cqlApiClient, eventName);
Future<JSONArray> cqlResultFuture = executor.submit(cqlClientCallable);
executor.shutdown();
return cqlResultFuture;
我试图在下面提到的测试代码中使用Mockito,但由于myArray被声明为null(显而易见),因此返回null。我无法使用Mockito返回非null值。
Future<JSONArray> myArray = null;
Mockito.when(executor.submit(cqlClientCallable)).thenReturn(myArray);