Skip to content

Commit

Permalink
Test that a context’s ParameterResolver can resolve constructor args
Browse files Browse the repository at this point in the history
  • Loading branch information
marcphilipp committed Apr 9, 2017
1 parent 36c387e commit bae2768
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,25 @@ void templateWithDynamicParameterResolverIsInvoked() {
event(container("templateWithDynamicParameterResolver"), finishedSuccessfully())));
}

@Test
void contextParameterResolverCanResolveConstructorArguments() {
LauncherDiscoveryRequest request = request().selectors(
selectMethod(MyTestTemplateTestCaseWithConstructor.class, "template", "java.lang.String")).build();

ExecutionEventRecorder eventRecorder = executeTests(request);

assertRecordedExecutionEventsContainsExactly(eventRecorder.getExecutionEvents(), //
wrappedInContainerEvents(MyTestTemplateTestCase.class, //
event(container("template"), started()), //
event(dynamicTestRegistered("test-template-invocation:#1"), displayName("[1] foo")), //
event(test("test-template-invocation:#1"), started()), //
event(test("test-template-invocation:#1"), finishedSuccessfully()), //
event(dynamicTestRegistered("test-template-invocation:#2"), displayName("[2] bar")), //
event(test("test-template-invocation:#2"), started()), //
event(test("test-template-invocation:#2"), finishedSuccessfully()), //
event(container("template"), finishedSuccessfully())));
}

@Test
void templateWithDynamicTestInstancePostProcessorIsInvoked() {
LauncherDiscoveryRequest request = request().selectors(
Expand Down Expand Up @@ -415,6 +434,21 @@ void templateWithCloseableStream() {
}
}

@ExtendWith(StringParameterResolvingInvocationContextProvider.class)
static class MyTestTemplateTestCaseWithConstructor {

private final String constructorParameter;

MyTestTemplateTestCaseWithConstructor(String constructorParameter) {
this.constructorParameter = constructorParameter;
}

@TestTemplate
void template(String parameter) {
assertEquals(constructorParameter, parameter);
}
}

static class TestTemplateTestClassWithBeforeAndAfterEach {

private static List<String> lifecycleEvents = new ArrayList<>();
Expand Down

0 comments on commit bae2768

Please sign in to comment.