Java 类org.junit.jupiter.api.extension.TestTemplateInvocationContext 实例源码
项目:junit-dataprovider
文件:UseDataProviderInvocationContextProvider.java
@Override
protected Stream<TestTemplateInvocationContext> provideInvocationContexts(ExtensionContext context,
TEST_ANNOTATION annotation) {
Method testMethod = context.getRequiredTestMethod();
DataProviderResolverContext dataProviderResolverContext = getDataProviderResolverContext(context, annotation);
List<Method> dataProviderMethods = findDataProviderMethods(dataProviderResolverContext);
checkArgument(dataProviderMethods.size() > 0,
String.format("Could not find a dataprovider for test '%s' using resolvers '%s'.", testMethod,
dataProviderResolverContext.getResolverClasses()));
return dataProviderMethods.stream().flatMap(dpm -> {
DATAPROVIDER_ANNOTATION dataProviderAnnotation = dpm.getAnnotation(dataProviderAnnotationClass);
boolean cacheDataProviderResult = cacheDataProviderResult(dataProviderAnnotation);
Object data = invokeDataProviderMethodToRetrieveData(dpm, cacheDataProviderResult, context);
return convertData(testMethod, data, getConverterContext(dataProviderAnnotation))
.map(d -> (TestTemplateInvocationContext) new DataProviderInvocationContext(testMethod, d,
getDisplayNameContext(dataProviderAnnotation)));
});
}
项目:selenium-jupiter
文件:SeleniumExtension.java
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
ExtensionContext context) {
BrowsersTemplate browsers = null;
try {
String browserJsonContent = getString(
"sel.jup.browser.template.json.content");
if (browserJsonContent.isEmpty()) {
String browserJsonFile = getString(
"sel.jup.browser.template.json.file");
if (browserJsonFile.startsWith(CLASSPATH_PREFIX)) {
String browserJsonInClasspath = browserJsonFile
.substring(CLASSPATH_PREFIX.length());
browserJsonContent = IOUtils.toString(
this.getClass().getResourceAsStream(
"/" + browserJsonInClasspath),
defaultCharset());
} else {
browserJsonContent = new String(
readAllBytes(get(browserJsonFile)));
}
}
browsers = new Gson().fromJson(browserJsonContent,
BrowsersTemplate.class);
} catch (IOException e) {
throw new SeleniumJupiterException(e);
}
return browsers.getStream().map(b -> invocationContext(b, this));
}
项目:junit-dataprovider
文件:AbstractDataProviderInvocationContextProvider.java
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
Method testMethod = context.getRequiredTestMethod();
return AnnotationUtils.findAnnotation(testMethod, testAnnotationClass)
.map(annotation -> provideInvocationContexts(context, annotation))
.orElseThrow(() -> new ExtensionConfigurationException(String.format(
"Could not find annotation '%s' on test method '%s'.", testAnnotationClass, testMethod)));
}
项目:junit-dataprovider
文件:DataProviderInvocationContextProvider.java
@Override
protected Stream<TestTemplateInvocationContext> provideInvocationContexts(ExtensionContext extensionContext,
TEST_ANNOTATION testAnnotation) {
Method testMethod = extensionContext.getRequiredTestMethod();
return convertData(testMethod, getData(testAnnotation), getConverterContext(testAnnotation))
.map(d -> new DataProviderInvocationContext(testMethod, d, getDisplayNameContext(testAnnotation)));
}
项目:junit-dataprovider
文件:AbstractDataProviderInvocationContextProviderTest.java
@BeforeEach
void setup() throws Exception {
underTest = new AbstractDataProviderInvocationContextProvider<Annotation>(testAnnotationClass, dataConverter) {
@Override
protected Stream<TestTemplateInvocationContext> provideInvocationContexts(ExtensionContext extensionContext,
Annotation testAnnotation) {
return null;
}
};
testMethod = this.getClass().getDeclaredMethod("setup");
MockitoAnnotations.initMocks(this);
}
项目:mastering-junit5
文件:MyTestTemplateInvocationContextProvider.java
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
ExtensionContext context) {
return Stream.of(invocationContext("parameter-1"),
invocationContext("parameter-2"));
}
项目:golden-master
文件:RunInvocationContextProvider.java
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
int repetitions = determineRepetitions(context);
return IntStream.range(0, repetitions).boxed().map(index -> new IndexedRunInvocationContext(index, outputFile));
}
项目:Mastering-Software-Testing-with-JUnit-5
文件:MyTestTemplateInvocationContextProvider.java
@Override
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(
ExtensionContext context) {
return Stream.of(invocationContext("parameter-1"),
invocationContext("parameter-2"));
}
项目:junit-dataprovider
文件:AbstractDataProviderInvocationContextProvider.java
/**
* Method to provide annotation contexts in subclasses.
*
* @param extensionContext the extension context for the dataprovider test about to be invoked; never {@code null}
* @param testAnnotation which annotates the test
* @return a {@code Stream} of {@code TestTemplateInvocationContext} instances for the invocation of the
* dataprovider tests; never {@code null} or empty
* @throws IllegalArgumentException if and only if no {@link TestTemplateInvocationContext} could be provided
*/
protected abstract Stream<TestTemplateInvocationContext> provideInvocationContexts(ExtensionContext extensionContext,
TEST_ANNOTATION testAnnotation);