Class RunnableTestRuleAdapter

java.lang.Object
org.elasticsearch.test.junit.RunnableTestRuleAdapter
All Implemented Interfaces:
org.junit.rules.TestRule

public class RunnableTestRuleAdapter extends Object implements org.junit.rules.TestRule
Adapts a CheckedRunnable to a JUnit TestRule. The runnable is executed (CheckedRunnable.run()) when the Statement is evaluated, before the test is executed. That is, the supplied runnable represents a set-up step for the test. This is useful when a class needs some set-up code to be executed as part of a TestRule rather than a Before or BeforeClass annotated method. For example, if a test must run some set-up code before launching an ElasticsearchCluster that set-up code must be contained within a TestRule and chained to the cluster via a RuleChain. By using this adapter, the setup code can be expressed as a method reference as in the example below:

 @ClassRule
 public static TestRule ruleChain = RuleChain.outerRule(new RunnableTestRuleAdapter(MyTests::generateTestFiles)).around(cluster);
 
  • Constructor Details

    • RunnableTestRuleAdapter

      public RunnableTestRuleAdapter(org.elasticsearch.core.CheckedRunnable<Exception> runnable)
  • Method Details

    • apply

      public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
      Specified by:
      apply in interface org.junit.rules.TestRule