@Test
public void testValidateTestMethods() throws Throwable {
UnitilsMethodValidator methodValidator = new UnitilsMethodValidator(new TestClass(JustATestClass.class));
methodValidator.validateTestMethods(Test.class,false);
Assert.assertEquals(getErrors().get(0).getMessage(),methodValidator.getErrors().get(0).getMessage());
Assert.assertEquals(getErrors().get(1).getMessage(),methodValidator.getErrors().get(1).getMessage());
Assert.assertEquals(getErrors().get(2).getMessage(),methodValidator.getErrors().get(2).getMessage());
Assert.assertEquals(getErrors().get(3).getMessage(),methodValidator.getErrors().get(3).getMessage());
}
@Test
public void testGetParametersMethod() {
UnitilsMethodValidator methodValidator = new UnitilsMethodValidator(new TestClass(Testclass2.class));
methodValidator.validateInstanceMethods();
Assert.assertTrue(methodValidator.getErrors() != null && !methodValidator.getErrors().isEmpty());
Assert.assertEquals("No runnable methods",methodValidator.getErrors().get(0).getMessage());
}
项目: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
private List<Method> getTestMethods(TestClass testClass,Class<?> classUnderTest) {
List<Method> methods = testClass.getAnnotatedMethods(Test.class);
if (methods.isEmpty()) {
methods.addAll(getTestMethodsWithNoAnnotation(classUnderTest));
}
return 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"));
}
}
@Test
public void testValidateArgConstructorWithParameters() throws Exception {
UnitilsMethodValidator validator = new UnitilsMethodValidator(new TestClass(Testclass3.class));
validator.validateArgConstructor();
Assert.assertTrue(validator.getErrors().isEmpty());
}
项目:powermock
文件:PowerMockJUnit4MethodValidator.java
public PowerMockJUnit4MethodValidator(TestClass testClass) {
super(testClass);
}
项目:UnsafeAdapter
文件:JMHRunWith.java
public JMHRunWith(Class<?> klass) throws InitializationError {
fTestClass = new TestClass(klass);
fTestMethods = getTestMethods();
validate();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。