I have been mocking a test for a function ResultSetFuture, I used a example from Github (that works) for testing ResultSetFuture, but the code I am testing/mocking uses Futures#successfulAsList
as shown here. So in Line 34, the test just halts and never finishes. The code shown below is a portion of the test that halts.
ResultSetFuture future = Mockito.mock(ResultSetFuture.class);
Mockito.doReturn(result).when(future).get();
Mockito.doReturn(future).when(session).executeAsync(Mockito.anyString());
ResultSetFuture resultF = session.executeAsync("select value from table where key='a'");
Future<List<ResultSet>> data = Futures.successfulAsList(new ArrayList(){{ add(resultF); }});
List finished = data.get(); // <---- The test stops here
You need to mock the isDone
method in future
to indicate that the execution finished and avoid the code halting.
ResultSetFuture future = Mockito.mock(ResultSetFuture.class);
Mockito.doReturn(result).when(future).get();
Mockito.doReturn(future).when(session).executeAsync(Mockito.anyString());
Mockito.doReturn(true).when(future).isDone(); //<-- mock to avoid halting
ResultSetFuture resultF = session.executeAsync("select value from table where key='a'");
Future<List<ResultSet>> data = Futures.successfulAsList(Collections.singletonList(resultF));
List finished = data.get(); // <---- The test stops here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With