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

autofixture.publicinterface.PrivateGenerate Maven / Gradle / Ivy

The newest version!
package autofixture.publicinterface;

import autofixture.implementationdetails.CollectionFactory;
import autofixture.interfaces.InlineConstrainedGenerator;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;

import java.util.*;

import static autofixture.publicinterface.InlineGenerators.exploding;

/**
 * Created by grzes on 01.07.2017.
 */
class PrivateGenerate {
  public static final Fixture FIXTURE = new Fixture();

  static  T any(final TypeToken type, final InlineConstrainedGenerator generator) {
    return FIXTURE.create(type, generator);
  }

  static  T anyExploding(final TypeToken typeToken) {
    return Any.anonymous(exploding(typeToken));
  }

  static  Iterable manyAsIterableOf(
      final TypeToken typeToken, final InlineConstrainedGenerator omittedValues) {
    return manyAsListOf(typeToken, omittedValues);
  }

  static  T[] manyAsArrayOf(final TypeToken type) {
    return FIXTURE.createArray(type);
  }

  static  T[] manyAsArrayOf(final TypeToken typeToken, final InlineConstrainedGenerator omittedValues) {
    final List list = manyAsListOf(typeToken, omittedValues);
    T[] templateArray = CollectionFactory.createArray(typeToken, list.size());
    return list.toArray(templateArray);
  }

  static  List manyAsListOf(final TypeToken type) {
    return Lists.newArrayList(FIXTURE.createMany(type));
  }

  //TODO rethink putting this into the Fixture class
  static  List manyAsListOf(final TypeToken typeToken, final InlineConstrainedGenerator generator) {
    final List result = CollectionFactory.createList();
    result.add(any(typeToken, generator));
    result.add(any(typeToken, generator));
    result.add(any(typeToken, generator));

    return result;
  }

  private static  Collection manyAsCollectionOf(final TypeToken typeToken, final InlineConstrainedGenerator omittedValues) {
    return manyAsListOf(typeToken, omittedValues);
  }

  private static  Collection manyAsCollectionOf(final TypeToken instanceType) {
    return PrivateGenerate.FIXTURE.createMany(instanceType);
  }

  static  Set manyAsSetOf(final TypeToken type) {
    final Collection many = FIXTURE.createMany(type);
    final Set collection = CollectionFactory.createSetFrom(many);
    return collection;
  }

  static  Set manyAsSetOf(final TypeToken type, final InlineConstrainedGenerator omittedValues) {
    final Collection collection = manyAsCollectionOf(type, omittedValues);
    return CollectionFactory.createSetFrom(collection);
  }

  static  Queue manyAsQueueOf(final TypeToken type) {
    final Collection many = FIXTURE.createMany(type);
    final Queue queue = CollectionFactory.createQueueFrom(many);
    return queue;
  }

  static  Queue manyAsQueueOf(final TypeToken type, final InlineConstrainedGenerator omittedValues) {
    final Collection collection = manyAsCollectionOf(type, omittedValues);
    return CollectionFactory.createQueueFrom(collection);
  }

  static  Deque manyAsDequeOf(final TypeToken type) {
    final Collection many = FIXTURE.createMany(type);
    final Deque collection = CollectionFactory.createDequeFrom(many);
    return collection;
  }

  static  Deque manyAsDequeOf(final TypeToken type, final InlineConstrainedGenerator omittedValues) {
    final Collection collection = manyAsCollectionOf(type, omittedValues);
    return CollectionFactory.createDequeFrom(collection);
  }

  static  SortedSet manyAsSortedSetOf(final TypeToken type) {
    final Collection many = FIXTURE.createMany(type);
    final SortedSet collection = CollectionFactory.createSortedSetFrom(many);
    return collection;
  }

  static  SortedSet manyAsSortedSetOf(final TypeToken type, final InlineConstrainedGenerator omittedValues) {
    final Collection collection = manyAsCollectionOf(type, omittedValues);
    return CollectionFactory.createSortedSetFrom(collection);
  }

  static  SortedMap manyAsSortedMapBetween(final TypeToken key, final TypeToken value) {
    return CollectionFactory.createSortedMapFrom(manyAsMapBetween(key, value));
  }

  static  Map manyAsMapBetween(final TypeToken keyType, final TypeToken valueType) {
    final T[] keys = (T[]) manyAsCollectionOf(keyType).toArray();
    final V[] values = (V[]) manyAsCollectionOf(valueType).toArray();

    final Map map = CollectionFactory.createMapFrom(keys, values);

    return map;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy