| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.junit.rules.ExternalResource
public abstract class ExternalResource
A base class for Rules (like TemporaryFolder) that set up an external resource before a test (a file, socket, server, database connection, etc.), and guarantee to tear it down afterward:
 public static class UsesExternalResource {
        Server myServer= new Server();
 
        @Rule
        public ExternalResource resource= new ExternalResource() {
                @Override
                protected void before() throws Throwable {
                        myServer.connect();
                };
 
                @Override
                protected void after() {
                        myServer.disconnect();
                };
        };
 
        @Test
        public void testFoo() {
                new Client().run(myServer);
        }
 }
 
| Constructor Summary | |
|---|---|
| ExternalResource() | |
| Method Summary | |
|---|---|
| protected  void | after()Override to tear down your specific external resource. | 
|  Statement | apply(Statement base,
      FrameworkMethod method,
      Object target)Modifies the method-running Statementto implement an additional
 test-running rule. | 
| protected  void | before()Override to set up your specific external resource. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Constructor Detail | 
|---|
public ExternalResource()
| Method Detail | 
|---|
public final Statement apply(Statement base,
                             FrameworkMethod method,
                             Object target)
MethodRuleStatement to implement an additional
 test-running rule.
apply in interface MethodRulebase - The Statement to be modifiedmethod - The method to be runtarget - The object on with the method will be run.
base,
 a wrapper around base, or a completely new Statement.
protected void before()
               throws Throwable
if - setup fails (which will disable after
Throwableprotected void after()
if - setup fails (which will disable after| 
 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||