org.junit.internal.MethodSorter Java Examples

The following examples show how to use org.junit.internal.MethodSorter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardsTestClass.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected void scanAnnotatedMembers(final Map<Class<? extends Annotation>,
        List<FrameworkMethod>> methodsForAnnotations,
        final Map<Class<? extends Annotation>, List<FrameworkField>> fieldsForAnnotations) {
    for (final Class<?> eachClass : getSuperClasses(getJavaClass())) {
        for (final Method eachMethod : MethodSorter.getDeclaredMethods(eachClass)) {
            addToAnnotationLists(new FrameworkMethod(eachMethod), methodsForAnnotations);
        }
        // Fields are ignored
    }
    for (final  Map.Entry<Class<? extends Annotation>,
            List<FrameworkMethod>> methodsEntry : methodsForAnnotations.entrySet()) {
        final Class<? extends Annotation> key = methodsEntry.getKey();
        if (key == Test.class) {
            final List<FrameworkMethod> methods = methodsEntry.getValue();
            final List<FrameworkMethod> newMethods = new ArrayList<>(methods.size() * 2);
            for (final FrameworkMethod m : methods) {
                newMethods.add(new StandardsFrameworkMethod(m.getMethod(), false));
                newMethods.add(new StandardsFrameworkMethod(m.getMethod(), true));
            }
            methodsForAnnotations.put(key, newMethods);
        }
    }
}
 
Example #2
Source File: DistributedSQLTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@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);
    }
  }
}
 
Example #3
Source File: DistributedSQLTestBase.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@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);
    }
  }
}