private Statement statement(final Statement base) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
ClientAndServer clientAndServer;
if (perTestSuite) {
if (perTestSuiteClientAndServer == null) {
perTestSuiteClientAndServer = clientAndServerFactory.newClientAndServer();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
perTestSuiteClientAndServer.stop();
}
});
}
clientAndServer = perTestSuiteClientAndServer;
} else {
clientAndServer = clientAndServerFactory.newClientAndServer();
}
setMockServerClient(target, clientAndServer);
try {
base.evaluate();
} finally {
if (!perTestSuite) {
clientAndServer.stop();
}
}
}
};
}