Java Examples for org.junit.runner.Description
The following java examples will help you to understand the usage of org.junit.runner.Description. These source code samples are taken from different open source projects.
Example 1
Project: eclipselink.runtime-master File: SerializableDescription.java View source code |
/** * Create a SerializableDescription objects from an org.junit.runner.Description objects * @param description the org.junit.runner.Description object to be converted * @return the SerializableDescription object created from an org.junit.runner.Description object */ @SuppressWarnings("unchecked") public static SerializableDescription create(Description description) { final List<SerializableDescription> children; if (description.getChildren() != null) { children = new ArrayList<SerializableDescription>(); for (Description child : description.getChildren()) { children.add(create(child)); } } else { children = Collections.EMPTY_LIST; } return new SerializableDescription(description.getDisplayName(), children); }
Example 2
Project: AndroidSnooper-master File: RealmCleanRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} finally {
realm.beginTransaction();
realm.delete(HttpCall.class);
realm.delete(HttpHeader.class);
realm.delete(HttpHeaderValue.class);
realm.commitTransaction();
}
}
};
}
Example 3
Project: opslogger-master File: RestoreSystemStreamsFixture.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
InputStream originalSystemIn = System.in;
PrintStream originalSystemOut = System.out;
PrintStream originalSystemErr = System.err;
System.setIn(new NonCloseableInputStream(originalSystemIn));
System.setOut(new NonCloseablePrintStream(originalSystemOut));
System.setErr(new NonCloseablePrintStream(originalSystemErr));
try {
base.evaluate();
} finally {
System.setIn(originalSystemIn);
System.setOut(originalSystemOut);
System.setErr(originalSystemErr);
}
}
};
}
Example 4
Project: android-unit-testing-tutorial-master File: MethodNameExample.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
String className = description.getClassName();
String methodName = description.getMethodName();
base.evaluate();
System.out.println("Class name: " + className + ", method name: " + methodName);
}
};
}
Example 5
Project: junit-hierarchicalcontextrunner-master File: CapturingTestAndMethodRuleStub.java View source code |
// apply from TestRule
public Statement apply(Statement base, Description description) {
this.statementTestRuleApplyWasCalledWith = base;
this.descriptionTestRuleApplyWasCalledWith = description;
numberOfApplicationsOfTestRulesApplyMethod++;
return new Statement() {
@Override
public void evaluate() throws Throwable {
statementWasEvaluated = true;
}
};
}
Example 6
Project: memoryfilesystem-master File: PosixPermissionFileSystemRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
PosixPermissionFileSystemRule.this.fileSystem = MemoryFileSystemBuilder.newEmpty().addRoot(MemoryFileSystemProperties.UNIX_ROOT).setSeprator(MemoryFileSystemProperties.UNIX_SEPARATOR).addUser(OWNER).addGroup(OWNER).addUser(GROUP).addGroup(GROUP).addUser(OTHER).addGroup(OTHER).addFileAttributeView(PosixFileAttributeView.class).setCurrentWorkingDirectory("/home/" + OWNER).setStoreTransformer(StringTransformers.IDENTIY).setCaseSensitive(true).addForbiddenCharacter((char) 0).build("PosixPermissionFileSystemRule");
try {
base.evaluate();
} finally {
PosixPermissionFileSystemRule.this.fileSystem.close();
}
}
};
}
Example 7
Project: netbeans-gradle-project-master File: SwingTestsRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
if (description.getAnnotation(SwingTest.class) == null) {
return base;
}
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (SwingUtilities.isEventDispatchThread()) {
base.evaluate();
return;
}
try {
Thread.interrupted();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
try {
base.evaluate();
} catch (Throwable ex) {
throw new TestExceptionWrapper(ex);
}
}
});
} catch (InvocationTargetException ex) {
Throwable cause = ex.getCause();
if (cause instanceof TestExceptionWrapper) {
throw cause.getCause();
} else {
throw cause;
}
}
}
};
}
Example 8
Project: OpenChat-master File: RxPluginTestRule.java View source code |
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxAndroidPlugins.reset();
RxAndroidPlugins.setInitMainThreadSchedulerHandler( scheduler -> Schedulers.trampoline());
RxJavaPlugins.reset();
RxJavaPlugins.setIoSchedulerHandler( schedulerCallable -> Schedulers.trampoline());
base.evaluate();
RxAndroidPlugins.reset();
RxJavaPlugins.reset();
}
};
}
Example 9
Project: testcontainers-java-master File: FailureDetectingExternalResource.java View source code |
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<Throwable>();
starting(description);
try {
base.evaluate();
succeeded(description);
} catch (Throwable e) {
errors.add(e);
failed(e, description);
} finally {
finished(description);
}
MultipleFailureException.assertEmpty(errors);
}
};
}
Example 10
Project: afc-master File: PathWindingRuleTestRule.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
for (PathWindingRule rule : PathWindingRule.values()) {
try {
CURRENT_RULE = rule;
base.evaluate();
} catch (AssumptionViolatedException exception) {
}
}
}
};
}
Example 11
Project: burst-master File: ParentRunnerSpyTest.java View source code |
@Test
public void testGetFilteredChildren() throws Exception {
List<String> children = ParentRunnerSpy.getFilteredChildren(new ParentRunner<String>(ParentRunnerSpyTest.class) {
@Override
protected List<String> getChildren() {
ArrayList<String> children = new ArrayList<>();
children.add("children");
return children;
}
@Override
protected Description describeChild(String o) {
return null;
}
@Override
protected void runChild(String o, RunNotifier runNotifier) {
}
});
assertEquals(1, children.size());
assertEquals("children", children.get(0));
}
Example 12
Project: debop4j-master File: RequiresTransactionalCapabilitiesRule.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (TestHelper.backendSupportsTransactions()) {
base.evaluate();
} else {
log.info("Skipping test " + description.getMethodName() + " as the current GridDialect doesn't support transactions");
}
}
};
}
Example 13
Project: embedded-db-junit-master File: EmbeddedDatabaseRuleInitSqlFailedTest.java View source code |
@Test(expected = JdbcSQLException.class) public void name() throws Throwable { final EmbeddedDatabaseRule rule = EmbeddedDatabaseRule.builder().withInitialSqlFromResource("classpath:illegal.sql").build(); final Description testDescription = Description.createTestDescription(getClass(), "Test"); final Statement testStatement = rule.apply(statement, testDescription); testStatement.evaluate(); }
Example 14
Project: fitnesse-master File: DescriptionHelperTest.java View source code |
@Test
public void testGetWikiPageNoPageData() {
WikiPage page = mockWikiTestPage().getSourcePage();
Description desc = descriptionFactory.createDescription(getClass(), page);
WikiPage pageFound = DescriptionHelper.getWikiPage(desc);
assertSame(page, pageFound);
assertEquals(0, DescriptionHelper.getPageTags(pageFound).size());
}
Example 15
Project: junit-master File: ParentRunnerFilteringTest.java View source code |
private static Filter notThisMethodName(final String methodName) {
return new Filter() {
@Override
public boolean shouldRun(Description description) {
return description.getMethodName() == null || !description.getMethodName().equals(methodName);
}
@Override
public String describe() {
return "don't run method name: " + methodName;
}
};
}
Example 16
Project: junit4-master File: ParentRunnerFilteringTest.java View source code |
private static Filter notThisMethodName(final String methodName) {
return new Filter() {
@Override
public boolean shouldRun(Description description) {
return description.getMethodName() == null || !description.getMethodName().equals(methodName);
}
@Override
public String describe() {
return "don't run method name: " + methodName;
}
};
}
Example 17
Project: junit5-master File: UniqueIdReader.java View source code |
@Override public Serializable apply(Description description) { Optional<Object> result = readFieldValue(Description.class, fieldName, description); return result.map(Serializable.class::cast).orElseGet(() -> { logger.warning(() -> format("Could not read unique id for Description, using display name instead: %s", description.toString())); return description.getDisplayName(); }); }
Example 18
Project: ldap-test-utils-master File: LdapServerRule.java View source code |
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
ldapServer = new LdapServerResource(target);
try {
ldapServer.start();
base.evaluate();
} finally {
if (ldapServer.isStarted()) {
ldapServer.stop();
}
}
ldapServer = null;
}
};
}
Example 19
Project: less4j-master File: DeleteFilesRule.java View source code |
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
files = new ArrayList<File>();
try {
base.evaluate();
} finally {
for (File file : files) {
remove(file);
}
}
}
};
}
Example 20
Project: rngzip-master File: PreJUnit4TestCaseRunnerTest.java View source code |
@Test public void testListener() throws Exception { JUnitCore runner = new JUnitCore(); RunListener listener = new RunListener() { @Override public void testStarted(Description description) { assertEquals(Description.createTestDescription(OneTest.class, "testOne"), description); count++; } }; runner.addListener(listener); count = 0; Result result = runner.run(OneTest.class); assertEquals(1, count); assertEquals(1, result.getRunCount()); }
Example 21
Project: RoboBuggy-master File: ParentRunnerFilteringTest.java View source code |
private static Filter notThisMethodName(final String methodName) {
return new Filter() {
@Override
public boolean shouldRun(Description description) {
return description.getMethodName() == null || !description.getMethodName().equals(methodName);
}
@Override
public String describe() {
return "don't run method name: " + methodName;
}
};
}
Example 22
Project: RxAndroidOrm-master File: RxJavaSchedulersTestRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
resetPlugins();
RxJavaPlugins.setIoSchedulerHandler(new Function<Scheduler, Scheduler>() {
@Override
public Scheduler apply(@NonNull Scheduler scheduler) throws Exception {
return Schedulers.trampoline();
}
});
base.evaluate();
resetPlugins();
}
};
}
Example 23
Project: sampleng-backend-master File: VeiculoResourceCondition.java View source code |
@Override
public void prepare(Description description) {
MongoOperations mongoOperation = (MongoOperations) ApplicationContextProvider.getApplicationContext().getBean("mongoTemplate");
Veiculo veiculo = createVeiculo();
Condutor proprietario = veiculo.getProprietario();
mongoOperation.insert(proprietario);
mongoOperation.insert(veiculo);
OBJECT.set(veiculo);
}
Example 24
Project: smos-box-master File: AcceptanceTestRunner.java View source code |
@Override public void run(RunNotifier runNotifier) { if (runAcceptanceTests) { super.run(runNotifier); } else { final Description description = Description.createTestDescription(clazz, "allMethods. Acceptance tests disabled. Set VM param -Drun.acceptance.test=true to enable."); runNotifier.fireTestIgnored(description); } }
Example 25
Project: sosies-generator-master File: ParentRunnerFilteringTest.java View source code |
private static Filter notThisMethodName(final String methodName) {
return new Filter() {
@Override
public boolean shouldRun(Description description) {
return description.getMethodName() == null || !description.getMethodName().equals(methodName);
}
@Override
public String describe() {
return "don't run method name: " + methodName;
}
};
}
Example 26
Project: yobi-master File: ExecutionTimeWatcher.java View source code |
@Override
protected void finished(Description description) {
this.end = new DateTime();
Interval interval = new Interval(start, end);
if (interval.toDurationMillis() / 1000 > 3) {
Logger.debug("[0;35m" + description.getMethodName() + ": " + interval.toDurationMillis() / 1000 + " sec[0m");
} else {
Logger.debug(description.getMethodName() + ": " + interval.toDurationMillis() / 1000 + " sec");
}
}
Example 27
Project: junit-rules-master File: ExpectedExceptions.java View source code |
/** * {@inheritDoc} * * @see org.junit.rules.TestRule#apply(org.junit.runners.model.Statement, org.junit.runner.Description) */ @Override public final Statement apply(final Statement base, final Description description) { final Class<?> testClass = description.getTestClass(); final String methodName = description.getMethodName(); try { final Method method = testClass.getMethod(methodName); if (method == null) { fail("getMethod(\"" + methodName + "\") returned null!"); } final Throws throwsAnnotation = method.getAnnotation(Throws.class); if (throwsAnnotation == null) { return base; } final Class<? extends Throwable> expected = throwsAnnotation.value(); return new Statement() { @Override public void evaluate() throws Throwable { try { base.evaluate(); fail("Expected exception " + expected.getName() + " not thrown!"); } catch (final Throwable t) { if (!expected.isInstance(t)) { throw t; } } } }; } catch (final SecurityException e) { throw new RuntimeException(e); } catch (final NoSuchMethodException e) { throw new RuntimeException(e); } }
Example 28
Project: org.openntf.domino-master File: JUnit4TestClassReference.java View source code |
private void sendDescriptionTree(final IVisitsTestTrees notified, org.junit.runner.Description description) { if (description.isTest()) { notified.visitTreeEntry(new JUnit4Identifier(description), false, 1); } else { notified.visitTreeEntry(new JUnit4Identifier(description), true, description.getChildren().size()); for (Description child : description.getChildren()) { sendDescriptionTree(notified, child); } } }
Example 29
Project: agile-itsm-master File: MockInitialContextRule.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
System.setProperty(Context.INITIAL_CONTEXT_FACTORY, MockInitialContextFactory.class.getName());
MockInitialContextFactory.setCurrentContext(context);
try {
base.evaluate();
} finally {
System.clearProperty(Context.INITIAL_CONTEXT_FACTORY);
MockInitialContextFactory.clearCurrentContext();
}
}
};
}
Example 30
Project: AndroidJUnit4-master File: JUnit4HasMethodAnnotation.java View source code |
public boolean apply(Description description) {
Method method;
//For Parametarized
String methodName = description.getMethodName();
if (methodName == null) {
return false;
}
int parameterIndex = methodName.indexOf('[');
if (parameterIndex > -1) {
methodName = methodName.substring(0, parameterIndex);
}
try {
method = description.getTestClass().getMethod(methodName);
} catch (NoSuchMethodException e) {
return false;
}
// }
return method.getAnnotation(annotationClass) != null;
// return description.getAnnotation(annotationClass) != null;
}
Example 31
Project: ArchUnit-master File: CodingRulesWithRunnerMethodsIntegrationTest.java View source code |
@ArchTest
public static void no_java_util_logging_as_method(final JavaClasses classes) {
ExpectedViolation expectViolation = ExpectedViolation.none();
expectViolationByUsingJavaUtilLogging(expectViolation);
expectViolation.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
CodingRulesWithRunnerMethodsTest.no_java_util_logging_as_method(classes);
}
}, Description.createTestDescription(CodingRulesWithRunnerMethodsIntegrationTest.class, "no_java_util_logging_as_method"));
}
Example 32
Project: arquillian-cube-master File: NetworkDslRule.java View source code |
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
List<Throwable> errors = new ArrayList<>();
network = networkBuilder.build();
final org.arquillian.cube.docker.impl.client.config.Network dockerNetwork = network.getNetwork();
String networkId = null;
try {
networkId = dockerClientExecutor.createNetwork(network.getId(), dockerNetwork);
dockerNetwork.addMetadata(IsNetworkContainerObject.class, new IsNetworkContainerObject());
base.evaluate();
} catch (Throwable t) {
errors.add(t);
} finally {
if (networkId != null) {
dockerClientExecutor.removeNetwork(networkId);
}
}
MultipleFailureException.assertEmpty(errors);
}
};
}
Example 33
Project: build-monitor-master File: SandboxJenkinsHome.java View source code |
@Override
public TestRule applyTo(final JenkinsInstance jenkins) {
return new TestWatcher() {
@Override
protected void starting(Description test) {
Path jenkinsHome = temporaryJenkinsHomeFor(test);
Log.info("Setting jenkins home to {}", jenkinsHome);
jenkins.setHome(jenkinsHome);
}
};
}
Example 34
Project: es6draft-master File: ExceptionHandler.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} catch (Throwable t) {
if (matcher.matches(t)) {
handle(t);
} else {
throw t;
}
}
}
};
}
Example 35
Project: find-master File: UserRoleStrategy.java View source code |
@Override
protected boolean matchesSafely(final Description description) {
final Optional<Role> maybeMethodAnnotation = Optional.ofNullable(description.getAnnotation(Role.class));
final Optional<Role> maybeAnnotation = maybeMethodAnnotation.isPresent() ? maybeMethodAnnotation : Optional.ofNullable(description.getTestClass().getAnnotation(Role.class));
if (maybeAnnotation.isPresent()) {
final UserRole requiredRole = maybeAnnotation.get().value();
return requiredRole == activeRole;
} else {
return true;
}
}
Example 36
Project: frodo-master File: ObservableRule.java View source code |
@Override
public Statement apply(Statement statement, Description description) {
final TestJoinPoint testJoinPoint = new TestJoinPoint.Builder(declaringType).withReturnType(Observable.class).withReturnValue(OBSERVABLE_STREAM_VALUE).build();
final TestProceedingJoinPoint testProceedingJoinPoint = new TestProceedingJoinPoint(testJoinPoint);
frodoProceedingJoinPoint = new FrodoProceedingJoinPoint(testProceedingJoinPoint);
observableInfo = new ObservableInfo(frodoProceedingJoinPoint);
return statement;
}
Example 37
Project: fuwesta-master File: AuthRule.java View source code |
/**
* {@inheritDoc}
*/
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
String username = "admin";
String password = "123";
boolean specialUser = false;
final Auth authInfo = description.getAnnotation(Auth.class);
AuthModule authModule = new AuthModule();
if (authInfo != null) {
username = authInfo.user();
password = authInfo.password();
authModule.logoutIfNecessary();
specialUser = true;
}
if (specialUser || !authModule.isLogedIn()) {
authModule.openLoginMask();
authModule.login(username, password, false);
}
try {
base.evaluate();
} finally {
if (specialUser) {
authModule.logout();
}
}
}
};
}
Example 38
Project: hibernate-ogm-master File: RequiresTransactionalCapabilitiesRule.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (TestHelper.backendSupportsTransactions()) {
base.evaluate();
} else {
log.infof("Skipping test $s as the current GridDialect doesn't support transactions", description.getMethodName());
}
}
};
}
Example 39
Project: jarup-master File: WorkingCopyRule.java View source code |
@Override
public Statement apply(final Statement statement, Description description) {
final TemporaryFolder tmp = new TemporaryFolder();
return tmp.apply(new Statement() {
@Override
public void evaluate() throws Throwable {
try {
wc = WorkingCopy.prepareFor(getJarUnderTest(tmp, jar));
statement.evaluate();
} finally {
if (wc != null) {
wc.close();
}
}
}
}, description);
}
Example 40
Project: jconditions-master File: ConditionTestRunner.java View source code |
/**
* {@inheritDoc}
*/
@Override
protected void runChild(final FrameworkMethod method, final RunNotifier notifier) {
final Description description = describeChild(method);
if (isIgnored(method)) {
notifier.fireTestIgnored(description);
} else {
final InvokeMethod statement = (InvokeMethod) methodBlock(method);
final Object test = ReflexUtils.getFieldValue(statement, "target");
final ConditionChecker<?> checker = ConditionCheckerEngine.detectFailedChecker(test, method);
if (checker != null) {
notifier.fireTestIgnored(description);
} else {
runLeaf(statement, description, notifier);
}
}
}
Example 41
Project: jenkins-build-monitor-plugin-master File: BrowserStackTestSessionName.java View source code |
@Override
protected void starting(Description description) {
// fixme: this seems a bit hacky, but that's the best we can do before improving the SerenityTestRunner
EnvironmentVariables props = Injectors.getInjector().getInstance(EnvironmentVariables.class);
props.setProperty("browserstack.name", humanReadable(description));
props.setProperty("browserstack.project", projectName);
if (!"".equalsIgnoreCase(build)) {
props.setProperty("browserstack.build", "");
}
}
Example 42
Project: kawala-master File: SingleTestExecutor.java View source code |
public void runSingleTest(Description description) {
try {
notifier.fireTestStarted(description);
doWork();
} catch (AssertionError e) {
notifier.fireTestFailure(new Failure(description, e));
} catch (Exception e) {
notifier.fireTestFailure(new Failure(description, e));
} finally {
notifier.fireTestFinished(description);
}
}
Example 43
Project: liferay-portal-master File: ArquillianUtil.java View source code |
public static boolean isArquillianTest(Description description) {
RunWith runWith = description.getAnnotation(RunWith.class);
if (runWith == null) {
return false;
}
Class<? extends Runner> runnerClass = runWith.value();
String runnerClassName = runnerClass.getName();
if (runnerClassName.equals("com.liferay.arquillian.extension.junit.bridge.junit." + "Arquillian")) {
return true;
}
return false;
}
Example 44
Project: mockito-master File: RetryRule.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
for (int remainingAttempts = attempts; remainingAttempts > 0; remainingAttempts--) {
try {
base.evaluate();
} catch (Throwable throwable) {
if (remainingAttempts < 0) {
throw new AssertionError(format("Tried this test + %d times and failed", attempts)).initCause(throwable);
}
}
}
}
};
}
Example 45
Project: MovieGuide-master File: RxSchedulersOverrideRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxAndroidPlugins.getInstance().reset();
RxAndroidPlugins.getInstance().registerSchedulersHook(rxAndroidSchedulersHook);
RxJavaHooks.reset();
RxJavaHooks.setOnIOScheduler(rxJavaImmediateScheduler);
RxJavaHooks.setOnNewThreadScheduler(rxJavaImmediateScheduler);
base.evaluate();
RxAndroidPlugins.getInstance().reset();
RxJavaHooks.reset();
}
};
}
Example 46
Project: MPS-master File: OrderComparator.java View source code |
@Override public int compare(Description a, Description b) { if (a.getTestClass() != b.getTestClass()) { return a.getTestClass().getName().compareTo(b.getTestClass().getName()); } if (a.getMethodName().equals(b.getMethodName())) { return 0; } Order oaa = a.getAnnotation(Order.class); int orderA = (oaa != null ? oaa.value() : -1); Order oab = b.getAnnotation(Order.class); int orderB = (oab != null ? oab.value() : -1); if (orderA >= 0 || orderB >= 0) { return orderA - orderB; } // default order for (Method m : a.getTestClass().getMethods()) { if (m.getName().equals(a.getMethodName())) { return -1; } else if (m.getName().equals(b.getMethodName())) { return 1; } } throw new IllegalArgumentException("Method(s) not found : either " + a + " or " + b); }
Example 47
Project: mvn-dev-proxy-master File: SocketRule.java View source code |
@Override
public Statement apply(final Statement statement, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
statement.evaluate();
if (!checkProvidedPorts()) {
throw new AssertionFailedError("All ports have not been released");
}
}
};
}
Example 48
Project: mylyn.docs-master File: TimeoutActionRule.java View source code |
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
Timer timer = new Timer(true);
try {
timer.schedule(createActionTask(), timeoutDuration.toMillis(), timeoutDuration.toMillis());
base.evaluate();
} finally {
timer.cancel();
}
}
};
}
Example 49
Project: ocelli-master File: RetryFailedTestRule.java View source code |
public Statement apply(final Statement base, final Description description) {
Retry retry = description.getAnnotation(Retry.class);
final int retryCount = retry == null ? 1 : retry.value();
return new Statement() {
@Override
public void evaluate() throws Throwable {
Throwable caughtThrowable = null;
for (attemptNumber = 0; attemptNumber <= retryCount; ++attemptNumber) {
try {
base.evaluate();
System.err.println(description.getDisplayName() + ": attempt number " + attemptNumber + " succeeded");
return;
} catch (Throwable t) {
caughtThrowable = t;
System.err.println(description.getDisplayName() + ": attempt number " + attemptNumber + " failed:");
System.err.println(t.toString());
}
}
System.err.println(description.getDisplayName() + ": giving up after " + retryCount + " failures.");
throw caughtThrowable;
}
};
}
Example 50
Project: OpenJML-master File: IgnoreFalseAssumptions.java View source code |
@Override
protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (method.getAnnotation(Ignore.class) != null) {
notifier.fireTestIgnored(description);
} else {
//runLeaf(methodBlock(method), description, notifier);
Statement statement = methodBlock(method);
EachTestNotifier eachNotifier = new EachTestNotifier(notifier, description);
eachNotifier.fireTestStarted();
try {
statement.evaluate();
} catch (AssumptionViolatedException e) {
eachNotifier.fireTestIgnored();
} catch (Throwable e) {
eachNotifier.addFailure(e);
} finally {
eachNotifier.fireTestFinished();
}
}
}
Example 51
Project: OpenSpotLight-master File: ErrorReportingRequest.java View source code |
@Override public Runner getRunner() { List<Throwable> goofs = getCauses(fCause); CompositeRunner runner = new CompositeRunner(fClass.getName()); for (int i = 0; i < goofs.size(); i++) { final Description description = Description.createTestDescription(fClass, "initializationError" + i); final Throwable throwable = goofs.get(i); runner.add(new ErrorReportingRunner(description, throwable)); } return runner; }
Example 52
Project: ovirt-engine-master File: RandomUtilsSeedingRule.java View source code |
@Override
public void starting(Description description) {
String seedProperty = System.getProperty(RANDOM_SEED_PROPERTY);
Long seed;
try {
seed = Long.parseLong(seedProperty);
} catch (NumberFormatException e) {
log.info("Property '{}' was not set, using System.currentTimeMillis() as a seed.", RANDOM_SEED_PROPERTY);
seed = System.currentTimeMillis();
}
log.info("Running test with random seed '{}'", seed);
RandomUtils.instance().setSeed(seed);
}
Example 53
Project: platform-java-master File: JUnitDescriptionGenerator.java View source code |
public Description createDescriptionFrom(ScenarioDefinition scenario, Steps... candidateSteps) { Description scenarioDescription = Description.createTestDescription(candidateSteps[0].getClass(), scenario.getTitle()); DescriptionTextUniquefier uniquefier = new DescriptionTextUniquefier(); for (String stringStep : scenario.getSteps()) { for (Steps candidates : candidateSteps) { for (CandidateStep candidate : candidates.getSteps()) { if (candidate.matches(stringStep)) { String uniqueString = uniquefier.getUniqueDescription(getJunitSafeString(stringStep)); scenarioDescription.addChild(Description.createTestDescription(candidates.getClass(), uniqueString + " - Scenario: " + scenario.getTitle() + "")); } } } } return scenarioDescription; }
Example 54
Project: pretty-master File: UiThreadRule.java View source code |
@Override
public Statement apply(final Statement statement, Description description) {
Collection<Annotation> annotations = description.getAnnotations();
for (Annotation annotation : annotations) {
if (UiThreadTest.class.equals(annotation.annotationType())) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final Throwable[] t = new Throwable[1];
instrumentation.runOnMainSync(new Runnable() {
@Override
public void run() {
try {
statement.evaluate();
} catch (Throwable throwable) {
t[0] = throwable;
}
}
});
if (t[0] != null) {
throw t[0];
}
}
};
}
}
return statement;
}
Example 55
Project: qualitymatters-master File: MockWebServerRule.java View source code |
@Override
@NonNull
public Statement apply(@NonNull Statement base, @NonNull Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final NeedsMockWebServer needsMockWebServer = description.getAnnotation(NeedsMockWebServer.class);
if (needsMockWebServer != null) {
final MockWebServer mockWebServer = new MockWebServer();
mockWebServer.start();
TestUtils.app().applicationComponent().changeableBaseUrl().setBaseUrl(mockWebServer.url("").toString());
if (!needsMockWebServer.setupMethod().isEmpty()) {
final Method setupMethod = testClassInstance.getClass().getDeclaredMethod(needsMockWebServer.setupMethod(), MockWebServer.class);
setupMethod.invoke(testClassInstance, mockWebServer);
}
// Try to evaluate the test and anyway shutdown the MockWebServer.
try {
base.evaluate();
} finally {
mockWebServer.shutdown();
}
} else {
// No need to setup a MockWebServer, just evaluate the test.
base.evaluate();
}
}
};
}
Example 56
Project: querydsl-master File: TargetRule.java View source code |
private boolean isExecuted(Description description, Target target) {
ExcludeIn ex = description.getAnnotation(ExcludeIn.class);
// excluded in given targets
if (ex != null && Arrays.asList(ex.value()).contains(target)) {
return false;
}
// included only in given targets
IncludeIn in = description.getAnnotation(IncludeIn.class);
if (in != null && !Arrays.asList(in.value()).contains(target)) {
return false;
}
return true;
}
Example 57
Project: qxwebdriver-java-master File: OnFailed.java View source code |
/**
* Takes a screenshot if a test fails.
*/
@Override
protected void failed(Throwable e, Description description) {
String autName = System.getProperty("org.qooxdoo.demo.autname");
String browserName = System.getProperty("org.qooxdoo.demo.browsername");
String browserVersion = System.getProperty("org.qooxdoo.demo.browserversion");
String platformName = System.getProperty("org.qooxdoo.demo.platform");
long now = System.currentTimeMillis();
String fileName = String.valueOf(now) + " " + autName + " " + browserName + " " + browserVersion + " " + platformName + ".png";
String tempDir = System.getProperty("java.io.tmpdir");
String path = tempDir + "/" + fileName;
File scrFile = ((TakesScreenshot) IntegrationTest.driver.getWebDriver()).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, new File(path));
} catch (IOException e1) {
System.err.println("Couldn't save screenshot: " + e1.getMessage());
e1.printStackTrace();
}
System.out.println("Saved screenshot as " + path);
}
Example 58
Project: Red-master File: ShellProvider.java View source code |
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
shell = new Shell(Display.getDefault());
shell.open();
base.evaluate();
} finally {
if (shell != null && !shell.isDisposed()) {
shell.close();
shell.dispose();
}
shell = null;
}
}
};
}
Example 59
Project: retrofit-master File: RxJavaPluginsResetRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxJavaPlugins.getInstance().reset();
try {
base.evaluate();
} finally {
RxJavaPlugins.getInstance().reset();
}
}
};
}
Example 60
Project: scott-master File: ScottReportingRule.java View source code |
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
/*
* Evaluate test and in case of a failure
* throw a new error with the correct exception type
* that contains Scott's output and the original cause.
*/
try {
base.evaluate();
} catch (AssertionError assertionError) {
throw new AssertionError(FailureRenderer.render(description, assertionError), assertionError);
} catch (Error error) {
throw new Error(FailureRenderer.render(description, error), error);
} catch (Throwable throwable) {
throw new Throwable(FailureRenderer.render(description, throwable), throwable);
}
}
};
}
Example 61
Project: simplelenium-master File: PrintTestName.java View source code |
@Override
protected void starting(Description description) {
System.out.println("----------------------------------------------------------------------");
System.out.println(description.getTestClass().getSimpleName() + "." + description.getMethodName());
System.out.println("----------------------------------------------------------------------");
}
Example 62
Project: sisyphus-master File: DataProvider.java View source code |
@Override
public Statement apply(final Statement statement, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
DataResource dataResource = description.getAnnotation(DataResource.class);
resourceName = dataResource.resourceName();
templateName = dataResource.templateName();
targetClass = dataResource.targetClass();
statement.evaluate();
}
};
}
Example 63
Project: spotify-tv-master File: FailureScreenshotRule.java View source code |
public void setupFailureHandler(Description description) {
final String testClassName = description.getClassName();
final String testMethodName = description.getMethodName();
final Context context = InstrumentationRegistry.getTargetContext();
Espresso.setFailureHandler(new FailureHandler() {
@Override
public void handle(Throwable throwable, Matcher<View> matcher) {
SpoonScreenshotAction.perform("espresso_assertion_failed", testClassName, testMethodName);
new DefaultFailureHandler(context).handle(throwable, matcher);
}
});
}
Example 64
Project: spring-ide-master File: AutobuildingEnablement.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
public void evaluate() throws Throwable {
boolean wasAutoBuilding = StsTestUtil.isAutoBuilding();
StsTestUtil.setAutoBuilding(enable);
try {
base.evaluate();
} finally {
StsTestUtil.setAutoBuilding(wasAutoBuilding);
}
}
};
}
Example 65
Project: substeps-runner-master File: JunitLegacyDescriptionBuilderTest.java View source code |
@Test
@Ignore("This currently won't run, as the legacy description builder uses reflection to invoke a constructor that doesn't exist in junit 4.11")
public void canCreateDescription() {
final IExecutionNode node = mock(IExecutionNode.class);
when(node.getDepth()).thenReturn(2);
when(node.getDescription()).thenReturn("A description");
Description description = descriptionBuilder.descriptionFor(node, new DescriptorStatus());
assertThat(description.getDisplayName(), is("0-1: A description"));
}
Example 66
Project: TestNG-master File: JUnit4TestMethod.java View source code |
private static ConstructorOrMethod getMethod(Description desc) {
Class<?> c = desc.getTestClass();
String method = desc.getMethodName();
if (JUnit4SpockMethod.isSpockClass(c)) {
return new JUnit4SpockMethod(desc);
}
if (method == null) {
return new JUnit4ConfigurationMethod(c);
}
// remove [index] from method name in case of parameterized test
int idx = method.indexOf('[');
if (idx != -1) {
method = method.substring(0, idx);
}
try {
return new ConstructorOrMethod(c.getMethod(method));
} catch (Throwable t) {
Utils.log("JUnit4TestMethod", 2, "Method '" + method + "' not found in class '" + c.getName() + "': " + t.getMessage());
return null;
}
}
Example 67
Project: testyourquery-master File: TestYourQueryRunner.java View source code |
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
Description description = describeChild(method);
if (isIgnored(method)) {
// log.debug("Test: "+method.getName()+" ignored");
notifier.fireTestIgnored(description);
} else {
runner.beforeRunTest(method);
// log.debug("Start Test");
runLeaf(methodBlock(method), description, notifier);
runner.afterRunTest();
}
}
Example 68
Project: uaa-master File: ScreenshotOnFail.java View source code |
@Override
protected void failed(Throwable e, Description description) {
TakesScreenshot takesScreenshot = (TakesScreenshot) browser;
File scrFile = takesScreenshot.getScreenshotAs(OutputType.FILE);
File destFile = getDestinationFile(description);
try {
FileUtils.copyFile(scrFile, destFile);
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
Example 69
Project: vertx-unit-master File: Timeout.java View source code |
@Override
public Statement apply(Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
VertxUnitRunner.pushTimeout(value);
try {
base.evaluate();
} finally {
VertxUnitRunner.popTimeout();
}
}
};
}
Example 70
Project: yum-repo-server-master File: MongoTestContext.java View source code |
@Override
public Statement apply(final Statement baseStatement, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
mongoProcessHolder = LocalMongoFactory.createMongoProcess();
try {
baseStatement.evaluate();
} finally {
stopMongo();
}
}
};
}
Example 71
Project: zohhak-master File: OrParentFilterTest.java View source code |
@Test public void filteringTest() { // given Description parent = Description.createSuiteDescription("method(class)"); Description child = Description.createSuiteDescription("method [2](class)"); // when when(filter.shouldRun(parent)).thenReturn(true); when(filter.shouldRun(child)).thenReturn(false); // then assertThat(orParentFilter.shouldRun(parent)).isTrue(); assertThat(orParentFilter.shouldRun(child)).isTrue(); }
Example 72
Project: maven-surefire-master File: Scheduler.java View source code |
/** * Attempts to stop all actively executing tasks and immediately returns a collection * of descriptions of those tasks which have started prior to this call. * <br> * This scheduler and other registered schedulers will stop, see {@link #register(Scheduler)}. * If <tt>shutdownNow</tt> is set, waiting methods will be interrupted via {@link Thread#interrupt}. * * @param stopNow if {@code true} interrupts waiting test methods * @return collection of descriptions started before shutting down */ protected ShutdownResult describeStopped(boolean stopNow) { Collection<Description> executedTests = new ConcurrentLinkedQueue<Description>(); Collection<Description> incompleteTests = new ConcurrentLinkedQueue<Description>(); stop(executedTests, incompleteTests, false, stopNow); return new ShutdownResult(executedTests, incompleteTests); }
Example 73
Project: substeps-eclipse-plugin-master File: JUnit4TestClassReference.java View source code |
private void sendDescriptionTree(final IVisitsTestTrees notified, final org.junit.runner.Description description) { if (description.isTest()) { notified.visitTreeEntry(new JUnit4Identifier(description), false, 1); } else { notified.visitTreeEntry(new JUnit4Identifier(description), true, description.getChildren().size()); for (final Description child : description.getChildren()) { sendDescriptionTree(notified, child); } } }
Example 74
Project: surefire-master File: Scheduler.java View source code |
/** * Attempts to stop all actively executing tasks and immediately returns a collection * of descriptions of those tasks which have started prior to this call. * <br> * This scheduler and other registered schedulers will stop, see {@link #register(Scheduler)}. * If <tt>shutdownNow</tt> is set, waiting methods will be interrupted via {@link Thread#interrupt}. * * @param stopNow if {@code true} interrupts waiting test methods * @return collection of descriptions started before shutting down */ protected ShutdownResult describeStopped(boolean stopNow) { Collection<Description> executedTests = new ConcurrentLinkedQueue<Description>(); Collection<Description> incompleteTests = new ConcurrentLinkedQueue<Description>(); stop(executedTests, incompleteTests, false, stopNow); return new ShutdownResult(executedTests, incompleteTests); }
Example 75
Project: tap4j-master File: TapListener.java View source code |
/** * Called right before any tests from a specific class are run. * * @see org.junit.runner.notification.RunListener#testRunStarted(org.junit.runner.Description) */ public void testRunStarted(Description description) throws Exception { if (isYaml()) { DumperOptions options = new DumperOptions(); options.setPrintDiagnostics(true); Representer representer = new Tap13Representer(options); this.tapProducer = new TapProducer(representer); } else { this.tapProducer = new TapProducer(); } this.testMethodsList = new LinkedList<JUnitTestData>(); }
Example 76
Project: eclipse.jdt.ui-master File: DescriptionMatcher.java View source code |
@Override
public boolean matches(Description description) {
String className = description.getClassName();
if (fClassName.equals(className)) {
String methodName = description.getMethodName();
if (methodName != null) {
return fLeadingIdentifier.equals(extractLeadingIdentifier(methodName));
}
}
return false;
}
Example 77
Project: powermock-master File: SelfieTest.java View source code |
void assert_getStaticMessage(RunNotifier notifier, Description currentTest, Matcher<? super String> getStaticMessageExpectation) {
notifier.fireTestStarted(currentTest);
try {
String staticMessage = StaticAndInstanceDemo.getStaticMessage();
if (getStaticMessageExpectation.matches(staticMessage)) {
notifier.fireTestFinished(currentTest);
} else {
notifier.fireTestFailure(new Failure(currentTest, new AssertionError("Unexpected #getStaticMessage() return-value: " + staticMessage)));
}
} catch (Exception ex) {
notifier.fireTestFailure(new Failure(currentTest, ex));
}
}
Example 78
Project: adf-selenium-master File: ScreenshotOnFailure.java View source code |
@Override
protected void failed(Throwable t, Description description) {
String oldWindow = driver.getWindowHandle();
try {
Set<String> windows = driver.getWindowHandles();
int idx = 0;
String baseFileName = description.getClassName() + "-" + description.getMethodName();
for (String guid : windows) {
StringBuilder fileName = new StringBuilder(baseFileName);
if (windows.size() > 1) {
fileName.append("-").append((idx++));
}
fileName.append(".png");
File file = new File(basedir, fileName.toString());
file.getCanonicalFile().getParentFile().mkdirs();
logger.info("*************** dumping error screenshot " + file.getCanonicalPath());
try {
driver.switchTo().window(guid);
((TakesScreenshot) driver).getScreenshotAs(new FileOutputType(file));
} catch (RuntimeException e) {
e.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
throw new WebDriverException(e);
} finally {
// restore original active window
driver.switchTo().window(oldWindow);
}
}
Example 79
Project: aerogear-testing-tools-master File: TestRuleExecutionTest.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
public void evaluate() throws Throwable {
testRuleCounter.incrementAndGet();
staticTestRuleCounter.incrementAndGet();
base.evaluate();
testRuleCounter.incrementAndGet();
staticTestRuleCounter.incrementAndGet();
}
;
};
}
Example 80
Project: alluxio-master File: TtlIntervalRule.java View source code |
@Override
public Statement apply(final Statement statement, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
long previousValue = TtlBucket.getTtlIntervalMs();
Whitebox.setInternalState(TtlBucket.class, "sTtlIntervalMs", mIntervalMs);
try {
statement.evaluate();
} finally {
Whitebox.setInternalState(TtlBucket.class, "sTtlIntervalMs", previousValue);
}
}
};
}
Example 81
Project: android-architecture-components-master File: TaskExecutorWithIdlingResourceRule.java View source code |
@Override
protected void starting(Description description) {
Espresso.registerIdlingResources(new IdlingResource() {
@Override
public String getName() {
return "architecture components idling resource";
}
@Override
public boolean isIdleNow() {
return TaskExecutorWithIdlingResourceRule.this.isIdle();
}
@Override
public void registerIdleTransitionCallback(ResourceCallback callback) {
callbacks.add(callback);
}
});
super.starting(description);
}
Example 82
Project: Android-Boilerplate-master File: RxSchedulersOverrideRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxAndroidPlugins.getInstance().reset();
RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
callResetViaReflectionIn(RxJavaPlugins.getInstance());
RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
base.evaluate();
RxAndroidPlugins.getInstance().reset();
callResetViaReflectionIn(RxJavaPlugins.getInstance());
}
};
}
Example 83
Project: Android-Code-Challenge-master File: RxSchedulersOverrideRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxAndroidPlugins.getInstance().reset();
RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
RxJavaPlugins.getInstance().reset();
RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
base.evaluate();
RxAndroidPlugins.getInstance().reset();
RxJavaPlugins.getInstance().reset();
}
};
}
Example 84
Project: android-mvp-architecture-master File: TestComponentRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
setupDaggerTestComponentInApplication();
base.evaluate();
} finally {
mTestComponent = null;
}
}
};
}
Example 85
Project: android-mvp-starter-master File: TestComponentRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
MvpStarterApplication application = MvpStarterApplication.get(mContext);
application.setComponent(mTestComponent);
base.evaluate();
application.setComponent(null);
}
};
}
Example 86
Project: AndroidEspressoIdlingResourcePlayground-master File: ActivityRule.java View source code |
@Override
public final Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
launchActivity();
base.evaluate();
if (!activity.isFinishing()) {
activity.finish();
}
// Eager reference kill in case someone leaked our reference.
activity = null;
}
};
}
Example 87
Project: AndroidTvBoilerplate-master File: RxSchedulersOverrideRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxAndroidPlugins.getInstance().reset();
RxAndroidPlugins.getInstance().registerSchedulersHook(mRxAndroidSchedulersHook);
callResetViaReflectionIn(RxJavaPlugins.getInstance());
RxJavaPlugins.getInstance().registerSchedulersHook(mRxJavaSchedulersHook);
base.evaluate();
RxAndroidPlugins.getInstance().reset();
callResetViaReflectionIn(RxJavaPlugins.getInstance());
}
};
}
Example 88
Project: ansible-plugin-master File: DslJobRule.java View source code |
private void before(Description description) throws Exception {
FreeStyleProject job = jRule.createFreeStyleProject();
String script = description.getAnnotation(WithJobDsl.class).value();
String scriptText = Resources.toString(Resources.getResource(script), Charsets.UTF_8);
job.getBuildersList().add(new ExecuteDslScripts(new ExecuteDslScripts.ScriptLocation(null, null, scriptText), false, RemovedJobAction.DELETE, RemovedViewAction.DELETE, LookupStrategy.JENKINS_ROOT));
jRule.buildAndAssertSuccess(job);
assertThat(jRule.getInstance().getJobNames(), hasItem(is(JOB_NAME_IN_DSL_SCRIPT)));
generated = jRule.getInstance().getItemByFullName(JOB_NAME_IN_DSL_SCRIPT, FreeStyleProject.class);
}
Example 89
Project: arquillian-container-osgi-master File: JUnitBundleTestRunner.java View source code |
@Override
protected List<RunListener> getRunListeners() {
RunListener listener = new RunListener() {
public void testStarted(Description description) throws Exception {
// [ARQ-1880] Workaround to reset the TCCL before the test is called
Thread.currentThread().setContextClassLoader(null);
}
};
return Collections.singletonList(listener);
}
Example 90
Project: arquillian-core-master File: TestingTestRuleInnerStatement.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
assertNotNull(ruleResources);
return new Statement() {
@ArquillianResource
private ResourceStub statementResources;
@Override
public void evaluate() throws Throwable {
ResourceAssertion.assertNotNullAndNotEqual(statementResources, ruleResources);
base.evaluate();
}
};
}
Example 91
Project: asakusafw-master File: AnnotationProcessing.java View source code |
@Override
public Statement apply(Statement base, Description description) {
this.statement = base;
return new Statement() {
@Override
public void evaluate() throws Throwable {
OperatorCompilerTestRoot runner = new OperatorCompilerTestRoot();
try {
beforeCompile(runner);
runner.start(AnnotationProcessing.this);
} finally {
runner.tearDown();
}
}
};
}
Example 92
Project: astrix-master File: AutoCloseableRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} finally {
for (AutoCloseable ac : autoClosables) {
AstrixTestUtil.closeQuiet(ac);
}
}
}
};
}
Example 93
Project: aws-java-sdk-master File: RetryRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
retry(base, 1);
}
public void retry(final Statement base, int attempts) throws Throwable {
try {
base.evaluate();
} catch (Exception e) {
if (attempts > maxRetryAttempts) {
throw e;
}
System.out.println("Test failed. Retrying with delay of: " + delay + " " + timeUnit);
timeUnit.sleep(delay);
retry(base, ++attempts);
}
}
};
}
Example 94
Project: aws-sdk-java-master File: RetryRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
retry(base, 1);
}
public void retry(final Statement base, int attempts) throws Throwable {
try {
base.evaluate();
} catch (Exception e) {
if (attempts > maxRetryAttempts) {
throw e;
}
System.out.println("Test failed. Retrying with delay of: " + delay + " " + timeUnit);
timeUnit.sleep(delay);
retry(base, ++attempts);
}
}
};
}
Example 95
Project: Barista-master File: FlakyActivityStatementBuilderTest.java View source code |
@Test public void allowFlakyStatementReturnedWhenNoAnnotationsFoundButUsesDefault() throws Exception { Statement baseStatement = new SomeStatement(); Description description = Description.EMPTY; Statement resultStatement = new FlakyActivityStatementBuilder().setBase(baseStatement).setDescription(description).allowFlakyAttemptsByDefault(5).build(); assertTrue(resultStatement instanceof AllowFlakyStatement); }
Example 96
Project: bazel-master File: HashBackedShardingFilter.java View source code |
@Override
public boolean shouldRun(Description description) {
if (description.isSuite()) {
return true;
}
int mod = description.getDisplayName().hashCode() % totalShards;
if (mod < 0) {
mod += totalShards;
}
if (mod < 0 || mod >= totalShards) {
throw new IllegalStateException();
}
return mod == shardIndex;
}
Example 97
Project: Bourbon-master File: TestComponentRule.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
BourbonApplication application = BourbonApplication.get(mContext);
application.setComponent(mTestComponent);
base.evaluate();
application.setComponent(null);
}
};
}
Example 98
Project: c5-replicator-master File: JUnitRuleFiberExceptions.java View source code |
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} catch (Throwable t) {
throwables.add(t);
}
MultipleFailureException.assertEmpty(throwables);
}
};
}
Example 99
Project: CallBuilder-master File: JUnit4TestAdapterCache.java View source code |
Test createTest(Description description) { if (description.isTest()) { return new JUnit4TestCaseFacade(description); } else { TestSuite suite = new TestSuite(description.getDisplayName()); for (Description child : description.getChildren()) { suite.addTest(asTest(child)); } return suite; } }
Example 100
Project: camunda-bpmn-model-master File: ParseBpmnModelRule.java View source code |
@Override
protected void starting(Description description) {
if (description.getAnnotation(BpmnModelResource.class) != null) {
Class<?> testClass = description.getTestClass();
String methodName = description.getMethodName();
String resourceFolderName = testClass.getName().replaceAll("\\.", "/");
String bpmnResourceName = resourceFolderName + "." + methodName + ".bpmn";
InputStream resourceAsStream = getClass().getClassLoader().getResourceAsStream(bpmnResourceName);
try {
bpmnModelInstance = Bpmn.readModelFromStream(resourceAsStream);
} finally {
IoUtil.closeSilently(resourceAsStream);
}
}
}
Example 101
Project: camunda-dmn-model-master File: GetDmnModelElementTypeRule.java View source code |
@Override
@SuppressWarnings("unchecked")
protected void starting(Description description) {
String className = description.getClassName();
assertThat(className).endsWith("Test");
className = className.substring(0, className.length() - "Test".length());
Class<? extends ModelElementInstance> instanceClass;
try {
instanceClass = (Class<? extends ModelElementInstance>) Class.forName(className);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
modelInstance = Dmn.createEmptyModel();
model = modelInstance.getModel();
modelElementType = model.getType(instanceClass);
}