コード例 #1
0
  Object invokeExplosively(FrameworkMethod it, Object target, Object... params) throws Throwable {
    Method method = it.getMethod();
    Class<?> testClass = target == null ? method.getDeclaringClass() : target.getClass();

    handleMockingOutsideTestMethods(it, target, testClass);

    // In case it isn't a test method, but a before/after method:
    if (it.getAnnotation(Test.class) == null) {
      if (shouldPrepareForNextTest && it.getAnnotation(Before.class) != null) {
        prepareForNextTest();
        shouldPrepareForNextTest = false;
      }

      TestRun.setRunningIndividualTest(target);
      TestRun.setSavePointForTestMethod(null);

      try {
        return it.invokeExplosively(target, params);
      } catch (Throwable t) {
        RecordAndReplayExecution.endCurrentReplayIfAny();
        StackTrace.filterStackTrace(t);
        throw t;
      } finally {
        if (it.getAnnotation(After.class) != null) {
          shouldPrepareForNextTest = true;
        }
      }
    }

    if (shouldPrepareForNextTest) {
      prepareForNextTest();
    }

    shouldPrepareForNextTest = true;

    try {
      executeTestMethod(it, target, params);
      return null; // it's a test method, therefore has void return type
    } catch (Throwable t) {
      StackTrace.filterStackTrace(t);
      throw t;
    } finally {
      /** modified by davey.wu * */
      TestRun.finishCurrentTestExecution(true);
      // TestRun.finishCurrentTestExecution(false);
      /** end modified by davey.wu * */
    }
  }
コード例 #2
0
  protected static boolean wasCalledDuringClassLoading() {
    if (LOCK.isHeldByCurrentThread()) return true;
    LOCK.lock();

    try {
      StackTrace st = new StackTrace(new Throwable());
      int n = st.getDepth();

      for (int i = 3; i < n; i++) {
        StackTraceElement ste = st.getElement(i);

        if ("ClassLoader.java".equals(ste.getFileName())
            && "loadClass".equals(ste.getMethodName())) {
          return true;
        }
      }

      return false;
    } finally {
      LOCK.unlock();
    }
  }