@Published(tag="architect") public abstract class TestEventDispatcherExtension extends java.lang.Object implements org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
このクラスは、 TestEventDispatcher が提供する JUnit 4 用の拡張機能を、
JUnit 5 の Extension の仕組みで再現する。
各 Extension はこのクラスを継承して作成することで、共通する部分の処理を省略できる。
| Modifier and Type | Field and Description |
|---|---|
protected TestEventDispatcher |
support
Extension が生成しテストクラスにインジェクションする、サポートクラスのインスタンス。
|
| Constructor and Description |
|---|
TestEventDispatcherExtension() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterAll(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
テストメソッドの後処理を実行する。
|
void |
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
テストメソッドの前処理を実行する。
|
protected abstract TestEventDispatcher |
createSupport(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context)
テストインスタンスにインジェクションするサポートクラスのインスタンスを生成する。
|
protected <A extends java.lang.annotation.Annotation> |
findAnnotation(java.lang.Object testInstance,
java.lang.Class<A> annotationClass)
指定されたテストインスタンスのクラスに設定されたアノテーションを取得する。
|
void |
postProcessTestInstance(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context) |
protected java.util.List<org.junit.rules.TestRule> |
resolveTestRules()
テストに対して適用する JUnit 4 の
TestRule のリストを取得する。 |
protected TestEventDispatcher support
このフィールドは、 postProcessTestInstance(Object, ExtensionContext) が実行されたときに初期化される。
設定される値は、 createSupport(Object, ExtensionContext) が返却したインスタンスが使用される。
public void postProcessTestInstance(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context)
throws java.lang.Exception
postProcessTestInstance in interface org.junit.jupiter.api.extension.TestInstancePostProcessorjava.lang.Exceptionprotected abstract TestEventDispatcher createSupport(java.lang.Object testInstance, org.junit.jupiter.api.extension.ExtensionContext context)
testInstance - テストインスタンスcontext - コンテキストpublic void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallbackpublic void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
throws java.lang.Exception
beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallbackcontext - コンテキストjava.lang.Exception - 例外がスローされた場合protected java.util.List<org.junit.rules.TestRule> resolveTestRules()
TestRule のリストを取得する。
JUnit 4 時代に作成した独自のサポートクラスを移植する場合は、
このメソッドをオーバーライドしてサポートクラスで宣言したルールインスタンスを
リストにして返却するように実装する。
オーバーライドした場合は、親クラスが返したリストに追加する形でルールを追加すること。
以下に実装例を示す。
public List<TestRule> resolveTestRules() {
// 親の resolveTestRules() が返したリストをベースにする
List<TestRule> testRules = new ArrayList<>(super.resolveTestRules());
// 独自の TestRule を追加する
testRules.add(((YourSupport)support).yourTestRule);
return testRules;
}
TestRule のリストpublic void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
throws java.lang.Exception
afterEach in interface org.junit.jupiter.api.extension.AfterEachCallbackcontext - コンテキストjava.lang.Exception - 例外がスローされた場合public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
afterAll in interface org.junit.jupiter.api.extension.AfterAllCallbackprotected <A extends java.lang.annotation.Annotation> A findAnnotation(java.lang.Object testInstance,
java.lang.Class<A> annotationClass)
A - アノテーションの型testInstance - テストインスタンス(null不可)annotationClass - 取得するアノテーションの型