Hi I am trying to do some unit tests with async methods. below is my code. the first line of methodUnderTest() where I mocked the doWork is returning null during execution and test fails. I tried different things related to async but nothing worked. What am I missing here.
public class AServiceImpl{
@Autowired
BService bService;
@Async
public CompletableFuture<String> methodUnderTest(String input){
String s = bService.doWork(input.substring(3));
//blah blah blah
return CompletableFuture.completedFuture(s);
}
}
public class AServiceTest{
private BService bService;
private AService aService;
@Before
void beforeTest(){
aService = new AServiceImpl();
bService = mock(BService.class);
//blah blah blah
}
@Test
public void someUnitTest(){
Mockito.when(bService.doWork(any())).thenReturn("ABC");
String s = aService.methodUnderTest("ABCDEF").get();
Assert.assertNotNull(s);
}
}