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

com.jparams.junit4.util.Parameters Maven / Gradle / Ivy

There is a newer version: 1.0.4
Show newest version
package com.jparams.junit4.util;

import com.jparams.junit4.data.ReadWith;
import com.jparams.junit4.reflection.Reflection;
import org.junit.runners.model.FrameworkMethod;

import java.lang.annotation.Annotation;

public final class Parameters {
    private Parameters() {
    }

    public static boolean isParameterized(FrameworkMethod method) {
        for (Annotation annotation : method.getAnnotations()) {
            if (annotation.annotationType().isAnnotationPresent(ReadWith.class)) {
                return true;
            }
        }

        return false;
    }

    public static Object[][] getParameterizedData(FrameworkMethod method) {
        for (Annotation annotation : method.getAnnotations()) {
            Class type = annotation.annotationType();

            if (type.isAnnotationPresent(ReadWith.class)) {
                ReadWith readWith = type.getAnnotation(ReadWith.class);
                return read(readWith, annotation);
            }
        }

        return null;
    }

    private static Object[][] read(ReadWith readWith, Annotation annotation) {
        com.jparams.junit4.data.reader.Reader reader = Reflection.createInstance(readWith.value());
        return reader.readData(annotation);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy