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

com.natpryce.makeiteasy.MakeItEasy Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
package com.natpryce.makeiteasy;

import com.natpryce.makeiteasy.sequence.ElementsSequence;

import java.util.*;

import static java.util.Arrays.asList;


/**
 * Syntactic sugar for using Make It Easy test-data builders.
 */
@SuppressWarnings("unused")
public class MakeItEasy {
    public static  Maker a(Instantiator instantiator, PropertyValue ... propertyProviders) {
        return new Maker<>(instantiator, propertyProviders);
    }
    
    public static  Maker an(Instantiator instantiator, PropertyValue ... propertyProviders) {
        return new Maker<>(instantiator, propertyProviders);
    }

    public static  PropertyValue with(Property property, W value) {
        return new PropertyValue<>(property, new SameValueDonor(value));
    }

    public static  PropertyValue with(W value, Property property) {
        return new PropertyValue<>(property, new SameValueDonor(value));
    }

    public static  PropertyValue with(Property property, Donor valueDonor) {
        return new PropertyValue<>(property, valueDonor);
    }

    public static  PropertyValue with(Donor valueDonor, Property property) {
        return new PropertyValue<>(property, valueDonor);
    }

    public static  PropertyValue withNull(Property property) {
        return new PropertyValue<>(property, new SameValueDonor(null));
    }

    public static  Donor theSame(Instantiator instantiator, PropertyValue ... propertyProviders) {
        return theSame(an(instantiator, propertyProviders));
    }
    
    public static  Donor theSame(Donor originalDonor) {
        return new SameValueDonor<>(originalDonor.value());
    }
    
    public static  T make(Maker maker) {
        return maker.value();
    }
    
    @SafeVarargs
    public static  Donor> listOf(Donor... donors) {
        return new NewCollectionDonor, T>(donors) {
            protected List newCollection() { return new ArrayList<>(); }
        };
    }
    
    @SafeVarargs
    public static  Donor> setOf(Donor... donors) {
        return new NewCollectionDonor, T>(donors) {
            protected Set newCollection() { return new HashSet<>(); }
        };
    }
    
    @SafeVarargs
    public static > Donor> sortedSetOf(Donor... donors) {
        return new NewCollectionDonor, T>(donors) {
            protected SortedSet newCollection() { return new TreeSet<>(); }
        };
    }
    
    public static  Donor from(final Iterable values) {
        return new ElementsSequence<>(values, Collections.emptyList());
    }

    @SafeVarargs
    public static  Donor from(T ... values) {
        return from(asList(values));
    }

    public static  Donor fromRepeating(Iterable values) {
        return new ElementsSequence<>(values, values);
    }

    @SafeVarargs
    public static  Donor fromRepeating(T ... values) {
        return fromRepeating(asList(values));
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy