All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tngtech.junit.dataprovider.AbstractStringDataProviderArgumentProvider Maven / Gradle / Ivy

Go to download

A TestNG like dataprovider runner for JUnit Jupiter Parameterized Tests which is largely compatible to JUnit4 dataprovider.

There is a newer version: 2.10
Show newest version
package com.tngtech.junit.dataprovider;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.stream.Stream;

import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.provider.Arguments;

import com.tngtech.junit.dataprovider.convert.ConverterContext;
import com.tngtech.junit.dataprovider.convert.DataConverter;

/**
 * Abstract class which provides the default implementation for creating a custom dataprovider annotation that provides
 * the data directly within itself.
 *
 * @param  annotation type used to provide the source data
 *
 * @see DataProvider#value()
 * @see StringDataProviderArgumentProvider
 */
public abstract class AbstractStringDataProviderArgumentProvider
        extends AbstractDataProviderArgumentProvider {

    protected AbstractStringDataProviderArgumentProvider(DataConverter dataConverter) {
        super(dataConverter);
    }

    protected AbstractStringDataProviderArgumentProvider() {
        super();
    }

    @Override
    public Stream provideArguments(ExtensionContext extensionContext) throws Exception {
        Method testMethod = extensionContext.getRequiredTestMethod();
        return convertData(testMethod, getData(sourceAnnotation), getConverterContext(sourceAnnotation));
    }

    /**
     * @param annotation on the test method which is providing the test data; never {@code null}
     * @return the test data to be converted and used with the annotated test method; never {@code null}
     */
    protected abstract Object getData(SOURCE_ANNOTATION annotation);

    /**
     * @param annotation on the test method which is providing the converter context; never {@code null}
     * @return the converter context used to convert the data to be used with the annotated test method; never
     *         {@code null}
     */
    protected abstract ConverterContext getConverterContext(SOURCE_ANNOTATION annotation);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy