コード例 #1
0
  private Method findPublicVoidMethod(Class<?> aClass, String methodName) {
    for (Method method : aClass.getDeclaredMethods()) {
      if (isPublic(method.getModifiers())
          && method.getReturnType() == void.class
          && methodName.equals(method.getName())) {
        return method;
      }
    }

    return null;
  }
コード例 #2
0
 private Object[] invokeParamsProvidingMethod(Class<?> testClass, Method provideMethod) {
   try {
     Object testObject = testClass.newInstance();
     provideMethod.setAccessible(true);
     Object[] params = (Object[]) provideMethod.invoke(testObject);
     return processParamsIfSingle(params);
   } catch (Exception e) {
     throw new RuntimeException(
         "Could not invoke method: "
             + provideMethod.getName()
             + " defined in class "
             + testClass
             + " so no params were used.",
         e);
   }
 }
コード例 #3
0
 private ArrayList<Object> gatherParamsFromAllMethodsFrom(Class<?> sourceClass) {
   ArrayList<Object> result = new ArrayList<Object>();
   Method[] methods = sourceClass.getDeclaredMethods();
   for (Method method : methods) {
     if (method.getName().startsWith("provide")) {
       if (!Modifier.isStatic(method.getModifiers()))
         throw new RuntimeException(
             "Parameters source method "
                 + method.getName()
                 + " is not declared as static. Modify it to a static method.");
       try {
         result.addAll(Arrays.asList(processParamsIfSingle((Object[]) method.invoke(null))));
       } catch (Exception e) {
         throw new RuntimeException(
             "Cannot invoke parameters source method: " + method.getName(), e);
       }
     }
   }
   return result;
 }
コード例 #4
0
  private void reportTestAsNotApplicableInCurrentTestRun(Method method) {
    Class<?> testClass = method.getDeclaringClass();
    Description testDescription = Description.createTestDescription(testClass, method.getName());

    runNotifier.fireTestAssumptionFailed(new Failure(testDescription, NOT_APPLICABLE));
  }
コード例 #5
0
 private boolean isTestNotApplicableInCurrentTestRun(
     Class<? extends Annotation> testAnnotation, Method testMethod) {
   return (testAnnotation == null || testMethod.getAnnotation(testAnnotation) != null)
       && new TestFilter(coverageMap).shouldIgnoreTestInCurrentTestRun(testMethod);
 }