The following method calls the method serveThis()
of a service
synchronously and the method serveThat()
in a separate thread i.e. asynchronously:
public void doSomething() {
service.serveThis();
new Thread(() -> service.serveThat()).start();
}
I want to verify in a unit test that service.serveThat()
will be executed asynchronously as according to the specification it must not be executed synchronously.
So, I want to prevent that later on someone just removes starting a new thread like this:
public void doSomething() {
service.serveThis();
// This synchronous execution must cause the test to fail
service.serveThat();
}