Java Code Examples for org.junit.runners.model.Statement#evaluate()

The following examples show how to use org.junit.runners.model.Statement#evaluate() . 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: RxJavaTestSchedulerRule.java    From JReadHub with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setComputationSchedulerHandler(scheduler -> mTestScheduler);
            RxJavaPlugins.setNewThreadSchedulerHandler(scheduler -> mTestScheduler);
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> mTestScheduler);

            try {
                base.evaluate();
            } finally {
                RxJavaPlugins.reset();
                RxAndroidPlugins.reset();
            }
        }
    };
}
 
Example 2
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			List<Throwable> errors = new ArrayList<Throwable>();

			startingQuietly(description, errors);
			try {
				base.evaluate();
				succeededQuietly(description, errors);
			} catch (AssumptionViolatedException e) {
				errors.add(e);
				skippedQuietly(e, description, errors);
			} catch (Throwable t) {
				errors.add(t);
				failedQuietly(t, description, errors);
			} finally {
				finishedQuietly(description, errors);
			}

			MultipleFailureException.assertEmpty(errors);
		}
	};
}
 
Example 3
Source File: LocaleRule.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            try {
                if (mLocales != null) {
                    mDeviceLocale = Locale.getDefault();
                    for (Locale locale : mLocales) {
                        setLocale(locale);
                        base.evaluate();
                    }
                }
            } finally {
                if (mDeviceLocale != null) {
                    setLocale(mDeviceLocale);
                }
            }
        }
    };
}
 
Example 4
Source File: ActivitiFormRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      List<Throwable> errors = new ArrayList<Throwable>();

      startingQuietly(description, errors);
      try {
        base.evaluate();
        succeededQuietly(description, errors);
      } catch (AssumptionViolatedException e) {
        errors.add(e);
        skippedQuietly(e, description, errors);
      } catch (Throwable t) {
        errors.add(t);
        failedQuietly(t, description, errors);
      } finally {
        finishedQuietly(description, errors);
      }

      MultipleFailureException.assertEmpty(errors);
    }
  };
}
 
Example 5
Source File: ErrorOutputChecker.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Statement apply(final Statement base, final Description description) {
    wrapSystemErr();

    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            try {
                base.evaluate();
                verifyNoOutput();
            }
            finally {
                restoreSystemErr();
            }
        }
    };
}
 
Example 6
Source File: RetryRule.java    From firebase-android-sdk with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      Throwable caughtThrowable = null;

      for (int i = 0; i < retryCount; i++) {
        try {
          base.evaluate();
          return;
        } catch (Throwable t) {
          caughtThrowable = t;
        }
      }

      throw caughtThrowable;
    }
  };
}
 
Example 7
Source File: RunTestUntilFail.java    From rqueue with Apache License 2.0 6 votes vote down vote up
private Statement statement(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      String testName = description.getMethodName();
      int i = 1;
      do {
        printData(
            "************* RUNNING Test: %s Iteration: %d *************", null, testName, i);
        try {
          base.evaluate();
          printData(
              "************* PASS Test: %s Iteration: %d  **************", null, testName, i);
          return;
        } catch (Throwable t) {
          performPostFailureActions(testName, i, t);
          if (i == retryCount) {
            throw t;
          }
        }
        i += 1;
      } while (i < retryCount);
    }
  };
}
 
Example 8
Source File: RedirectStdOutAndErr.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            originalStdOut = System.out;
            originalStdErr = System.err;
            try {
                System.setOut(stdOutPrintStream);
                System.setErr(stdErrPrintStream);
                base.evaluate();
            } finally {
                System.setOut(originalStdOut);
                System.setErr(originalStdErr);
                stdOutPrintStream = null;
                stdErrPrintStream = null;
                stdoutContent = null;
                stderrContent = null;
            }
        }
    };
}
 
Example 9
Source File: FirebaseAppRule.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      resetState();
      try {
        base.evaluate();
      } finally {
        resetState();
      }
    }
  };
}
 
Example 10
Source File: RedirectStdIn.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            originalStdIn = System.in;
            try {
                base.evaluate();
            } finally {
                System.setIn(originalStdIn);
                originalStdIn = null;
            }
        }
    };
}
 
Example 11
Source File: TestTopologyRule.java    From fluent-kafka-streams-tests with MIT License 5 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            TestTopologyRule.this.start();
            try {
                base.evaluate();
            } finally {
                TestTopologyRule.this.stop();
            }
        }
    };
}
 
Example 12
Source File: MockWebServerRule.java    From homeassist with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      server.start();
      base.evaluate();
      server.shutdown();
    }
  };
}
 
Example 13
Source File: RxJavaRule.java    From JReadHub with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
            base.evaluate();
        }
    };
}
 
Example 14
Source File: RedirectStdIn.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Statement apply(final Statement base, FrameworkMethod method, Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            originalStdIn = System.in;
            try {
                base.evaluate();
            } finally {
                System.setIn(originalStdIn);
                originalStdIn = null;
            }
        }
    };
}
 
Example 15
Source File: KafkaServerRule.java    From kafka-workers with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, FrameworkMethod method, Object target) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            try (KafkaServerScope scope = new KafkaServerScope(requiresKafkaServer(method))) {
                base.evaluate();
            }
        }
    };
}
 
Example 16
Source File: LegacyMockedSingleListenerRule.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @SuppressWarnings("unchecked")
        @Override
        public void evaluate() throws Throwable {
            resetSubscriberMock();
            base.evaluate();
        }
    };
}
 
Example 17
Source File: RxJavaRuler.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            RxJavaPlugins.reset();
            RxJavaPlugins.setIoSchedulerHandler(scheduler -> Schedulers.trampoline());
            RxAndroidPlugins.reset();
            RxAndroidPlugins.setMainThreadSchedulerHandler(scheduler -> Schedulers.trampoline());
            base.evaluate();
        }
    };
}
 
Example 18
Source File: AssumingPostgresEngine.java    From OpenCue with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            if (dbEngine == DatabaseEngine.POSTGRES) {
                base.evaluate();
            } else {
                throw new AssumptionViolatedException(
                        "Current database engine is " + dbEngine.toString() +
                        ", test requires POSTGRES. Skipping");
            }
        }
    };
}
 
Example 19
Source File: TestNameTestDirectoryProvider.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Statement apply(final Statement base, Description description) {
    init(description.getMethodName(), description.getTestClass().getSimpleName());
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            base.evaluate();
            getTestDirectory().maybeDeleteDir();
            // Don't delete on failure
        }
    };
}
 
Example 20
Source File: ParameterRule.java    From microprofile1.4-samples with MIT License 4 votes vote down vote up
private void ignoreStatementExecution(Statement base) {
    try {
        base.evaluate();
    } catch (Throwable ignored) {}
}