private Statement statement(final Statement base) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
ClientAndProxy clientAndProxy;
if (perTestSuite) {
if (perTestSuiteClientAndProxy == null) {
perTestSuiteClientAndProxy = clientAndProxyFactory.newClientAndProxy();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
perTestSuiteClientAndProxy.stop();
}
});
}
clientAndProxy = perTestSuiteClientAndProxy;
} else {
clientAndProxy = clientAndProxyFactory.newClientAndProxy();
}
setProxyClient(target, clientAndProxy);
try {
base.evaluate();
} finally {
if (!perTestSuite) {
clientAndProxy.stop();
}
}
}
};
}