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

autofixture.publicinterface.DefaultInlineGeneratorsFactory Maven / Gradle / Ivy

There is a newer version: 2.1.10
Show newest version
package autofixture.publicinterface;

import autofixture.interfaces.InlineConstrainedGenerator;
import autofixture.interfaces.InlineGeneratorsFactory;
import autofixture.interfaces.InlineInstanceGenerator;
import autofixture.publicinterface.constraints.OtherThanConstraint;
import autofixture.publicinterface.inline.*;
import autofixture.publicinterface.inline.strings.*;
import com.google.common.reflect.TypeToken;

/**
 * Created by astral on 28.03.15.
 */
public class DefaultInlineGeneratorsFactory implements InlineGeneratorsFactory {
  private static final String ALL_LETTERS = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
  private static final InlineInstanceGenerator ALPHA_CHAR_GENERATOR = new CharacterGenerator(
      ALL_LETTERS);
  private static final String ALL_DIGITS = "1029384756";
  private static final InlineInstanceGenerator DIGIT_CHAR_GENERATOR = new CharacterGenerator(
      ALL_DIGITS);
  private static final InlineInstanceGenerator PORT_NUMBER_GENERATOR = new PortNumberGenerator();
  private static final int MANY = 3;

  @Override
  public StringContainingSubstringGenerator stringContaining(final String str) {
    return new StringContainingSubstringGenerator(str);
  }

  @Override
  public AlphaStringGenerator alphaString(final int length) {
    return new AlphaStringGenerator(ALPHA_CHAR_GENERATOR,
        length);
  }

  @Override
  public InlineInstanceGenerator uppercaseString() {
    return new UppercaseStringGenerator(MANY, this);
  }

  @Override
  public InlineInstanceGenerator lowercaseString() {
    return new LowercaseStringGenerator(MANY, this);
  }

  @Override
  public InlineInstanceGenerator uppercaseString(final int length) {
    return new UppercaseStringGenerator(length, this);
  }

  @Override
  public InlineInstanceGenerator lowercaseString(final int length) {
    return new LowercaseStringGenerator(length, this);
  }


  @Override
  public IdentifierStringGenerator identifierString() {
    return new IdentifierStringGenerator(
        ALPHA_CHAR_GENERATOR, DIGIT_CHAR_GENERATOR, Generate.anyString().length());
  }

  @Override
  public InlineInstanceGenerator digitChar() {
    return DIGIT_CHAR_GENERATOR;
  }

  @Override
  public StringNotContainingSubstringsGenerator stringNotContaining(final String... excludedSubstrings) {
    return new StringNotContainingSubstringsGenerator(
        excludedSubstrings);
  }

  @Override
  public InlineInstanceGenerator alphaChar() {
    return ALPHA_CHAR_GENERATOR;
  }

  @Override
  public InlineInstanceGenerator stringOfLength(final int charactersCount) {
    return new StringOfLengthGenerator(charactersCount);
  }

  @Override
  public  ExplodingInstanceGenerator exploding(final TypeToken instance) {
    return new ExplodingInstanceGenerator<>(instance);
  }

  @Override
  public  InlineConstrainedGenerator otherThan(final T... omittedValues) {
    return new GenerationConstrainedByValueRejection<>(new OtherThanConstraint<>(omittedValues));
  }

  @Override
  public  InlineConstrainedGenerator without(final T... omittedValues) {
    return new GenerationConstrainedByValueRejection<>(new OtherThanConstraint<>(omittedValues));
  }

  @Override
  public InlineInstanceGenerator portNumber() {

    return PORT_NUMBER_GENERATOR;
  }

  @Override
  public AlphaStringGenerator alphaString() {
    return new AlphaStringGenerator(ALPHA_CHAR_GENERATOR,
        Generate.anyString().length());
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy