Last active
August 29, 2015 14:06
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DbCleanupRule implements TestRule { | |
private final DbConnectionManager connection; | |
public DbCleanupRule(DbConnectionManager connection) { | |
this.connection = connection; | |
} | |
@Override | |
public Statement apply(Statement base, Description description) { | |
return new DbCleanupStatement(base, connection); | |
} | |
private static final class DbCleanupStatement extends Statement { | |
private final Statement base; | |
private final DbConnectionManager connection; | |
private DbCleanupStatement(Statement base, DbConnectionManager connection) { | |
this.base = base; | |
this.connection = connection; | |
} | |
@Override | |
public void evaluate() throws Throwable { | |
try { | |
cleanDb(); | |
base.evaluate(); | |
} finally { | |
cleanDb(); | |
} | |
} | |
private void cleanDb() { | |
connection.doTheCleanup(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment