use of org.junit.internal.runners.statements.RunBefores in project spring-security-oauth by spring-projects.
the class OAuth2ContextSetup method initializeIfNecessary.
private void initializeIfNecessary(FrameworkMethod method, final Object target) {
final TestClass testClass = new TestClass(target.getClass());
OAuth2ContextConfiguration contextConfiguration = findOAuthContextConfiguration(method, testClass);
if (contextConfiguration == null) {
// Nothing to do
return;
}
this.initializeAccessToken = contextConfiguration.initialize();
this.resource = creatResource(target, contextConfiguration);
final List<FrameworkMethod> befores = testClass.getAnnotatedMethods(BeforeOAuth2Context.class);
if (!befores.isEmpty()) {
logger.debug("Running @BeforeOAuth2Context methods");
for (FrameworkMethod before : befores) {
RestOperations savedServerClient = clientHolder.getRestTemplate();
OAuth2ContextConfiguration beforeConfiguration = findOAuthContextConfiguration(before, testClass);
if (beforeConfiguration != null) {
OAuth2ProtectedResourceDetails resource = creatResource(target, beforeConfiguration);
AccessTokenRequest beforeRequest = new DefaultAccessTokenRequest();
beforeRequest.setAll(parameters);
OAuth2RestTemplate client = createRestTemplate(resource, beforeRequest);
clientHolder.setRestTemplate(client);
}
AccessTokenRequest request = new DefaultAccessTokenRequest();
request.setAll(parameters);
this.client = createRestTemplate(this.resource, request);
List<FrameworkMethod> list = Arrays.asList(before);
try {
new RunBefores(new Statement() {
public void evaluate() {
}
}, list, target).evaluate();
} catch (AssumptionViolatedException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (AssertionError e) {
throw e;
} catch (Throwable e) {
logger.debug("Exception in befores", e);
Assert.assertThat(e, CoreMatchers.not(CoreMatchers.anything()));
} finally {
clientHolder.setRestTemplate(savedServerClient);
}
}
}
}
use of org.junit.internal.runners.statements.RunBefores in project intellij-community by JetBrains.
the class GuiTestRunner method methodBlock.
@Override
protected Statement methodBlock(FrameworkMethod method) {
FrameworkMethod newMethod;
try {
if (Arrays.stream(getTestClass().getAnnotations()).anyMatch(annotation -> annotation instanceof ParentPlugin)) {
loadClassesWithNewPluginClassLoader();
} else {
loadClassesWithIdeClassLoader();
}
Method methodFromClassLoader = myTestClass.getJavaClass().getMethod(method.getName());
newMethod = new FrameworkMethod(methodFromClassLoader);
} catch (Exception e) {
return new Fail(e);
}
Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
}
}.run();
} catch (Throwable e) {
return new Fail(e);
}
Statement statement = methodInvoker(newMethod, test);
List<FrameworkMethod> beforeMethods = myTestClass.getAnnotatedMethods(Before.class);
if (!beforeMethods.isEmpty()) {
statement = new RunBefores(statement, beforeMethods, test);
}
List<FrameworkMethod> afterMethods = myTestClass.getAnnotatedMethods(After.class);
if (!afterMethods.isEmpty()) {
statement = new RunAfters(statement, afterMethods, test);
}
return statement;
}
use of org.junit.internal.runners.statements.RunBefores in project hazelcast by hazelcast.
the class AbstractHazelcastClassRunner method withBefores.
// Override withBefores to accommodate spawning the member bouncing thread after @Before's have been executed and before @Test
// when MemberBounceRule is in use
@Override
protected Statement withBefores(FrameworkMethod method, Object target, Statement statement) {
List<FrameworkMethod> befores = getTestClass().getAnnotatedMethods(Before.class);
List<TestRule> testRules = getTestRules(target);
Statement nextStatement = statement;
if (!testRules.isEmpty()) {
for (TestRule rule : testRules) {
if (rule instanceof BounceMemberRule) {
nextStatement = ((BounceMemberRule) rule).startBouncing(statement);
}
}
}
return befores.isEmpty() ? nextStatement : new RunBefores(nextStatement, befores, target);
}
use of org.junit.internal.runners.statements.RunBefores in project pact-jvm by DiUS.
the class InteractionRunner method withStateChanges.
protected Statement withStateChanges(final Interaction interaction, final Object target, final Statement statement) {
if (StringUtils.isNotEmpty(interaction.getProviderState())) {
final String state = interaction.getProviderState();
final List<FrameworkMethod> onStateChange = new ArrayList<FrameworkMethod>();
for (FrameworkMethod ann : testClass.getAnnotatedMethods(State.class)) {
for (String annotationState : ann.getAnnotation(State.class).value()) {
if (annotationState.equalsIgnoreCase(state)) {
onStateChange.add(ann);
break;
}
}
}
if (onStateChange.isEmpty()) {
return new Fail(new MissingStateChangeMethod("MissingStateChangeMethod: Did not find a test class method annotated with @State(\"" + state + "\")"));
}
return new RunBefores(statement, onStateChange, target);
} else {
return statement;
}
}
Aggregations