项目:powermock
文件:PowerMockJUnit4MethodValidator.java
@SuppressWarnings("unchecked")
@Override
public void validateInstanceMethods() {
validateTestMethods(After.class,false);
validateTestMethods(Before.class,false);
validateTestMethods(Test.class,false);
TestClass testClass = (TestClass) WhiteBox.getInternalState(this,"fTestClass",MethodValidator.class);
Class<?> classUnderTest = (Class<?>) WhiteBox.getInternalState(testClass,"fClass");
List<Throwable> fErrors = (List<Throwable>) WhiteBox.getInternalState(this,"fErrors",MethodValidator.class);
List<Method> methods = getTestMethods(testClass,classUnderTest);
if (methods.size() == 0)
fErrors.add(new Exception("No runnable methods"));
}
项目:powermock
文件:PowerMockJUnit4MethodValidator.java
/**
* This is a rip-off of the
* {@link MethodValidator#validateInstanceMethods()} with the exception that
* this method also searches for test methods if the class extends
* {@link TestCase} and has methods that starts with test which are not
* annotated.
*/
@SuppressWarnings("unchecked")
private void validateTestMethods(Class<? extends Annotation> annotation,boolean isstatic) {
TestClass testClass = (TestClass) WhiteBox.getInternalState(this,"fClass");
final List<Method> methods;
if (TestCase.class.equals(classUnderTest.getSuperclass()) && !isstatic) {
methods = getTestMethodsWithNoAnnotation(classUnderTest);
} else {
methods = testClass.getAnnotatedMethods(annotation);
}
List<Throwable> fErrors = (List<Throwable>) WhiteBox.getInternalState(this,MethodValidator.class);
for (Method each : methods) {
if (Modifier.isstatic(each.getModifiers()) != isstatic) {
String state = isstatic ? "should" : "should not";
fErrors.add(new Exception("Method " + each.getName() + "() " + state + " be static"));
}
if (!Modifier.isPublic(each.getDeclaringClass().getModifiers()))
fErrors.add(new Exception("Class " + each.getDeclaringClass().getName() + " should be public"));
if (!Modifier.isPublic(each.getModifiers()))
fErrors.add(new Exception("Method " + each.getName() + " should be public"));
if (each.getReturnType() != Void.TYPE)
fErrors.add(new Exception("Method " + each.getName() + " should be void"));
if (each.getParameterTypes().length != 0)
fErrors.add(new Exception("Method " + each.getName() + " should have no parameters"));
}
}
项目:UnsafeAdapter
文件:JMHRunWith.java
protected void validate() throws InitializationError {
MethodValidator methodValidator = new MethodValidator(fTestClass);
methodValidator.validateMethodsForDefaultRunner();
methodValidator.assertValid();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。