org.junit.jupiter.api.extension.ExtensionContext#getTestInstance()源码实例Demo

下面列出了org.junit.jupiter.api.extension.ExtensionContext#getTestInstance() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: tutorials   文件: SpringExtension.java
@Override
public void beforeEach(ExtensionContext context) throws Exception {
    Object testInstance = context.getTestInstance();
    Method testMethod = context.getTestMethod()
        .get();
    getTestContextManager(context).beforeTestMethod(testInstance, testMethod);
}
 
源代码2 项目: tutorials   文件: SpringExtension.java
@Override
public void afterEach(ExtensionContext context) throws Exception {
    Object testInstance = context.getTestInstance();
    Method testMethod = context.getTestMethod()
        .get();
    Throwable testException = context.getExecutionException()
        .orElse(null);
    getTestContextManager(context).afterTestMethod(testInstance, testMethod, testException);
}
 
源代码3 项目: jpa-unit   文件: JpaUnit.java
private TestInvocation createTestMethodInvocation(final ExtensionContext context, final boolean considerExceptions) {
    final JpaUnitContext ctx = JpaUnitContext.getInstance(context.getTestClass().get());

    return new TestInvocation() {

        @Override
        public Optional<Method> getTestMethod() {
            return context.getTestMethod();
        }

        @Override
        public ExecutionContext getContext() {
            return ctx;
        }

        @Override
        public Class<?> getTestClass() {
            return context.getTestClass().get();
        }

        @Override
        public Optional<Throwable> getException() {
            return considerExceptions ? context.getExecutionException() : Optional.empty();
        }

        @Override
        public FeatureResolver getFeatureResolver() {
            final FeatureResolver.Builder builder = FeatureResolver.newFeatureResolver(getTestClass());
            final Optional<Method> method = getTestMethod();
            if (method.isPresent()) {
                builder.withTestMethod(method.get());
            }
            return builder.build();
        }

        @Override
        public Optional<Object> getTestInstance() {
            return context.getTestInstance();
        }
    };
}