junitparams.internal.parameters.ParametersFromExternalClassProvideMethod Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JUnitParams Show documentation
Show all versions of JUnitParams Show documentation
Better parameterised tests for JUnit
package junitparams.internal.parameters;
import junitparams.Parameters;
import org.junit.runners.model.FrameworkMethod;
import javax.lang.model.type.NullType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
class ParametersFromExternalClassProvideMethod implements ParametrizationStrategy {
private final ParamsFromMethodCommon paramsFromMethodCommon;
private Parameters annotation;
ParametersFromExternalClassProvideMethod(FrameworkMethod frameworkMethod) {
this.paramsFromMethodCommon = new ParamsFromMethodCommon(frameworkMethod);
annotation = frameworkMethod.getAnnotation(Parameters.class);
}
@Override
public Object[] getParameters() {
Class> sourceClass = annotation.source();
return fillResultWithAllParamProviderMethods(sourceClass);
}
@Override
public boolean isApplicable() {
return annotation != null
&& !annotation.source().isAssignableFrom(NullType.class)
&& annotation.method().isEmpty();
}
private Object[] fillResultWithAllParamProviderMethods(Class> sourceClass) {
if (sourceClass.isEnum()) {
return sourceClass.getEnumConstants();
}
List