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

org.junit.experimental.theories.internal.SpecificDataPointsSupplier Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package org.junit.experimental.theories.internal;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.junit.experimental.theories.DataPoint;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.FromDataPoints;
import org.junit.experimental.theories.ParameterSignature;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.TestClass;

public class SpecificDataPointsSupplier extends AllMembersSupplier {

    public SpecificDataPointsSupplier(TestClass testClass) {
        super(testClass);
    }
    
    @Override
    protected Collection getSingleDataPointFields(ParameterSignature sig) {
        Collection fields = super.getSingleDataPointFields(sig);        
        String requestedName = sig.getAnnotation(FromDataPoints.class).value();

        List fieldsWithMatchingNames = new ArrayList();
        
        for (Field field : fields) {
            String[] fieldNames = field.getAnnotation(DataPoint.class).value();
            if (Arrays.asList(fieldNames).contains(requestedName)) {
                fieldsWithMatchingNames.add(field);
            }
        }
        
        return fieldsWithMatchingNames;
    }
    
    @Override
    protected Collection getDataPointsFields(ParameterSignature sig) {
        Collection fields = super.getDataPointsFields(sig);        
        String requestedName = sig.getAnnotation(FromDataPoints.class).value();
        
        List fieldsWithMatchingNames = new ArrayList();
        
        for (Field field : fields) {
            String[] fieldNames = field.getAnnotation(DataPoints.class).value();
            if (Arrays.asList(fieldNames).contains(requestedName)) {
                fieldsWithMatchingNames.add(field);
            }
        }
        
        return fieldsWithMatchingNames;
    }
    
    @Override
    protected Collection getSingleDataPointMethods(ParameterSignature sig) {
        Collection methods = super.getSingleDataPointMethods(sig);
        String requestedName = sig.getAnnotation(FromDataPoints.class).value();
        
        List methodsWithMatchingNames = new ArrayList();
        
        for (FrameworkMethod method : methods) {
            String[] methodNames = method.getAnnotation(DataPoint.class).value();
            if (Arrays.asList(methodNames).contains(requestedName)) {
                methodsWithMatchingNames.add(method);
            }
        }
        
        return methodsWithMatchingNames;
    }
    
    @Override
    protected Collection getDataPointsMethods(ParameterSignature sig) {
        Collection methods = super.getDataPointsMethods(sig);
        String requestedName = sig.getAnnotation(FromDataPoints.class).value();
        
        List methodsWithMatchingNames = new ArrayList();
        
        for (FrameworkMethod method : methods) {
            String[] methodNames = method.getAnnotation(DataPoints.class).value();
            if (Arrays.asList(methodNames).contains(requestedName)) {
                methodsWithMatchingNames.add(method);
            }
        }
        
        return methodsWithMatchingNames;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy