@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))); }); }
@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)); }
@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))); }
@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))); }
@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); }
@Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts( ExtensionContext context) { return Stream.of(invocationContext("parameter-1"), invocationContext("parameter-2")); }
@Override public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) { int repetitions = determineRepetitions(context); return IntStream.range(0, repetitions).boxed().map(index -> new IndexedRunInvocationContext(index, outputFile)); }
/** * 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);