I am writing Junit test for a Class in which CompletableFuture is implemented. I am trying to mock this piece of code but the test gets stuck infinitely on CompletableFuture.allOf(future1,future2).join();
The class on which I am writing junit:
class Sample{
@Autowired
Executor executor;
/*
piece of code
*/
void SampleMethod(request){
/*
some piece of code
*/
CompletableFuture<Obj1> future1 = CompletableFuture.SupplyAsync(
(Supplier<Obj1>) () -> {
return someClass.someMethod;
},executor);
CompletableFuture<Obj2> future2 = CompletableFuture.SupplyAsync(
(Supplier<Obj1>) () -> {
return someClass.someMethod;
},executor);
CompletableFuture.allOf(future1,future2).join();
}
My junit class looks like this:
class TestSample{
@Mock
Executor executor;
@Test
void testSampleMethod(){
MockedStatic<CompletableFuture> mock1 = Mockito.mockedStatic(CompletableFuture.class);
mock.when(()->CompletableFuture.supplyAsync(any(),any())).thenReturn(completedFuture);
}
}
I am new to junit. How to write junit for this?