The test of the synchronous method is very simple, and the execution status can be checked immediately after the call; while the asynchronous method, because we cannot know exactly when it will end, the previous method is to use Thread.sleep(500) to estimate an execution time. Then we usually estimate that it is longer than the actual time, which is very wasteful, and accidentally exceeding the estimated waiting time does not mean that there is a problem with the code. And the sleep method also throws a detection exception InterruptedException, usually a simple wrapper for Thread.sleep(), which is not very elegant. Therefore I recommend using Awaitility to test our asynchronous function code.
As it says:(Testing asynchronous systems is hard. Not only does it require handling threads, timeouts and concurrency issues, but the intent of the test code can be obscured by all these details. Awaitility is a DSL that allows you to express expectations of an asynchronous system in a concise and easy to read manner.) Awaitility complies with the apache 2.0 open source agreement https://github.com/awaitility/awaitility/blob/master/LICENSE I checked its dependencies to make sure it complies with the asf license. Best wishes! CalvinKirs
