Package org.elasticsearch.test.junit
Class RunnableTestRuleAdapter
java.lang.Object
org.elasticsearch.test.junit.RunnableTestRuleAdapter
- All Implemented Interfaces:
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 Summary
ConstructorDescriptionRunnableTestRuleAdapter
(org.elasticsearch.core.CheckedRunnable<Exception> runnable) -
Method Summary
Modifier and TypeMethodDescriptionorg.junit.runners.model.Statement
apply
(org.junit.runners.model.Statement base, org.junit.runner.Description description)
-
Constructor Details
-
RunnableTestRuleAdapter
-
-
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 interfaceorg.junit.rules.TestRule
-