I had to test some Java native concurrent code, and I had to mock some service with long running call the good solution for this purpose I found: https://medium.com/my-random-thoughts-in-software-engineering/get-rid-of-thread-sleep-e2abf3cadb6. My snippet is bit smaller:
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
ScheduledFuture<Integer> future = scheduler.schedule(() -> 1, 20000, TimeUnit.MILLISECONDS);
future.get();