提交 cd6f6b7a 编写于 作者: A Ahmed Ashour 提交者: skylot

test: add NotYetImplemented feature (PR #495)

上级 cdaecb31
package jadx;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates a test which is known to fail.
*
* <p>This would cause a failure to be considered as success and a success as failure,
* with the benefit of updating the related issue when it has been resolved even unintentionally.</p>
*
* <p>To have an effect, the test class must be annotated with:
*
* <code>
* &#064;ExtendWith(NotYetImplementedExtension.class)
* </code>
* </p>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface NotYetImplemented {
}
package jadx;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
public class NotYetImplementedExtension implements AfterTestExecutionCallback, TestExecutionExceptionHandler {
private Set<Method> knownFailedMethods = new HashSet<>();
@Override
public void handleTestExecutionException(ExtensionContext context, Throwable throwable) throws Throwable {
if (!isNotYetImplemented(context)) {
throw throwable;
}
knownFailedMethods.add(context.getTestMethod().get());
}
@Override
public void afterTestExecution(ExtensionContext context) throws Exception {
if (!knownFailedMethods.contains(context.getTestMethod().get())
&& isNotYetImplemented(context)
&& !context.getExecutionException().isPresent()) {
throw new AssertionError("Test "
+ context.getTestClass().get().getName() + '.' + context.getTestMethod().get().getName()
+ " is marked as @NotYetImplemented, but passes!");
}
}
private static boolean isNotYetImplemented(ExtensionContext context) {
return context.getTestMethod().get().getAnnotation(NotYetImplemented.class) != null
|| context.getTestClass().get().getAnnotation(NotYetImplemented.class) != null;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册