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

com.flextrade.jfixture.customisation.GreedyConstructorCustomisation Maven / Gradle / Ivy

Go to download

JFixture is an open source library based on the popular .NET library, AutoFixture

There is a newer version: 2.7.2
Show newest version
package com.flextrade.jfixture.customisation;

import com.flextrade.jfixture.ConstructorQuery;
import com.flextrade.jfixture.DefaultConstructorQuery;
import com.flextrade.jfixture.JFixture;
import com.flextrade.jfixture.SpecimenBuilder;
import com.flextrade.jfixture.builders.ClassToConstructorRelay;
import com.flextrade.jfixture.specifications.SpecificTypeSpecification;
import com.flextrade.jfixture.utility.SpecimenType;
import com.flextrade.jfixture.utility.comparators.ConstructorParameterCountComparator;
import com.flextrade.jfixture.utility.comparators.InverseComparator;

import java.lang.reflect.Constructor;
import java.lang.reflect.Type;

public class GreedyConstructorCustomisation implements Customisation {

    private final SpecimenType type;
    private final ConstructorQuery mostParameterCountConstructorQuery;

    public GreedyConstructorCustomisation(Type type) {
        this.type = SpecimenType.of(type);
        this.mostParameterCountConstructorQuery = new DefaultConstructorQuery(new InverseComparator>(new ConstructorParameterCountComparator()));
    }

    @Override
    public void customise(JFixture fixture) {
        SpecimenBuilder greedyConstructorRelay = new ClassToConstructorRelay(mostParameterCountConstructorQuery, new SpecificTypeSpecification(this.type));
        fixture.addBuilderToStartOfPipeline(greedyConstructorRelay);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy