本文整理汇总了Java中org.junit.internal.MethodSorter类的典型用法代码示例。如果您正苦于以下问题:Java MethodSorter类的具体用法?Java MethodSorter怎么用?Java MethodSorter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodSorter类属于org.junit.internal包,在下文中一共展示了MethodSorter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTestsFromTestCase
import org.junit.internal.MethodSorter; //导入依赖的package包/类
private void addTestsFromTestCase(final Class<?> theClass) {
fName = theClass.getName();
try {
getTestConstructor(theClass); // Avoid generating multiple error messages
} catch (NoSuchMethodException e) {
addTest(warning("Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()"));
return;
}
if (!Modifier.isPublic(theClass.getModifiers())) {
addTest(warning("Class " + theClass.getName() + " is not public"));
return;
}
Class<?> superClass = theClass;
List<String> names = new ArrayList<String>();
while (Test.class.isAssignableFrom(superClass)) {
for (Method each : MethodSorter.getDeclaredMethods(superClass)) {
addTestMethod(each, names, theClass);
}
superClass = superClass.getSuperclass();
}
if (fTests.size() == 0) {
addTest(warning("No tests found in " + theClass.getName()));
}
}
示例2: getAnnotatedMethods
import org.junit.internal.MethodSorter; //导入依赖的package包/类
public List<Method> getAnnotatedMethods(Class<? extends Annotation> annotationClass) {
List<Method> results = new ArrayList<Method>();
for (Class<?> eachClass : getSuperClasses(fClass)) {
Method[] methods = MethodSorter.getDeclaredMethods(eachClass);
for (Method eachMethod : methods) {
Annotation annotation = eachMethod.getAnnotation(annotationClass);
if (annotation != null && !isShadowed(eachMethod, results)) {
results.add(eachMethod);
}
}
}
if (runsTopToBottom(annotationClass)) {
Collections.reverse(results);
}
return results;
}
示例3: TestClass
import org.junit.internal.MethodSorter; //导入依赖的package包/类
/**
* Creates a {@code TestClass} wrapping {@code klass}. Each time this
* constructor executes, the class is scanned for annotations, which can be
* an expensive process (we hope in future JDK's it will not be.) Therefore,
* try to share instances of {@code TestClass} where possible.
*/
public TestClass(Class<?> klass) {
fClass = klass;
if (klass != null && klass.getConstructors().length > 1) {
throw new IllegalArgumentException(
"Test class can only have one constructor");
}
for (Class<?> eachClass : getSuperClasses(fClass)) {
for (Method eachMethod : MethodSorter.getDeclaredMethods(eachClass)) {
addToAnnotationLists(new FrameworkMethod(eachMethod),
fMethodsForAnnotations);
}
for (Field eachField : eachClass.getDeclaredFields()) {
addToAnnotationLists(new FrameworkField(eachField),
fFieldsForAnnotations);
}
}
}
示例4: setUp
import org.junit.internal.MethodSorter; //导入依赖的package包/类
@Override
public void setUp() throws Exception {
baseSetUp();
if (!beforeClassDone) {
beforeClass();
beforeClassDone = true;
}
if (lastTest == null) {
// for class-level afterClass, list the test methods and do the
// afterClass in the tearDown of last method
Class<?> scanClass = getClass();
while (Test.class.isAssignableFrom(scanClass)) {
for (Method m : MethodSorter.getDeclaredMethods(scanClass)) {
String methodName = m.getName();
if (methodName.startsWith("test")
&& m.getParameterTypes().length == 0
&& m.getReturnType().equals(Void.TYPE)) {
lastTest = methodName;
}
}
scanClass = scanClass.getSuperclass();
}
if (lastTest == null) {
fail("Could not find any last test in " + getClass().getName());
} else {
getLogWriter()
.info("Last test for " + getClass().getName() + ": " + lastTest);
}
}
}
示例5: findExpectedType
import org.junit.internal.MethodSorter; //导入依赖的package包/类
private static Class<?> findExpectedType(Class<?> fromClass) {
for (Class<?> c = fromClass; c != Object.class; c = c.getSuperclass()) {
for (Method method : MethodSorter.getDeclaredMethods(c)) {
if (isMatchesSafelyMethod(method)) {
return method.getParameterTypes()[0];
}
}
}
throw new Error("Cannot determine correct type for matchesSafely() method.");
}
示例6: scanAnnotatedMembers
import org.junit.internal.MethodSorter; //导入依赖的package包/类
protected void scanAnnotatedMembers(Map<Class<? extends Annotation>, List<FrameworkMethod>> methodsForAnnotations, Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations) {
for (Class<?> eachClass : getSuperClasses(fClass)) {
for (Method eachMethod : MethodSorter.getDeclaredMethods(eachClass)) {
addToAnnotationLists(new FrameworkMethod(eachMethod), methodsForAnnotations);
}
// ensuring fields are sorted to make sure that entries are inserted
// and read from fieldForAnnotations in a deterministic order
for (Field eachField : getSortedDeclaredFields(eachClass)) {
addToAnnotationLists(new FrameworkField(eachField), fieldsForAnnotations);
}
}
}