I have a callable FutureTask that is getting executed using ExecutorService.
FutureTask<Optional<Attestation>> attestationDbTask
= new FutureTask<Optional<Attestation>>(() -> attestationStore.get(imageInfo.getBucketKey()));
attestationStore.get(imageInfo.getBucketKey()) returns response of type Optional<Attestation>
Executing this task by calling
executorService.execute(attestationDbTask);
I am calling attestationDbTask.get(long, TimeUnit) method to get the execution result
attestation = attestationDbTask.get(AttestationServiceLimits.READ_ATTESTATION_PDB_TIME_OUT, TimeUnit.MILLISECONDS)
.orElseThrow(() -> generateNotFoundOrNotAuthorizedException(imageInfo + " in Attestation Store"));
I am trying to write unit test for this but the test get's stuck at attestationDbTask.get even though I have mocked the attestationStore.get to return the response for the callable.
when(attestationStore.get(anyString())).thenReturn(Optional.empty());
Can someone help with any pointers on how to go about mocking the futureTask.get method.