Class Fixture

    • Constructor Summary

      Constructors 
      Constructor Description
      Fixture()
      Creates a new Fixture with default configuration:
      Fixture​(Configuration configuration)
      Creates a new Fixture with given configuration
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      <T> void addManyTo​(Collection<T> result, SpecimenType<T> type)
      Adds objects of the specified SpecimenType<T>, recursively populated with random values, to the specified Collection<T> The number of objects created is specified in the Configuration under streamSize (default: 3)
      <T> void addManyTo​(Collection<T> result, Class<T> type)
      Adds objects of the specified Class<T>, recursively populated with random values, to the specified Collection<T> The number of objects created is specified in the Configuration under streamSize (default: 3)
      <T> ISpecimenBuilder<T> build​(SpecimenType<T> type)
      Creates a ISpecimenBuilder<T> to customise the object of type T to be created
      <T> ISpecimenBuilder<T> build​(Class<T> type)
      Creates a ISpecimenBuilder<T> to customise the object of type T to be created
      static Configuration configuration()
      Returns a new default configuration with the following values
      <T> T construct​(SpecimenType<T> type)
      Creates a new object of the specified type, using a random constructor if available
      <T> T construct​(Class<T> type)
      Creates a new object of the specified type, using a random constructor if available
      <T> T create​(SpecimenType<T> type)
      Creates a new object of the specified type, recursively populated with random values
      <T> T create​(Class<T> type)
      Creates a new object of the specified type, recursively populated with random values
      <T> Stream<T> createMany​(SpecimenType<T> type)
      Creates a Stream of objects of the specified type, recursively populated with random values
      <T> Stream<T> createMany​(Class<T> type)
      Creates a Stream of objects of the specified type, recursively populated with random values
      <T> Optional<T> createOptional​(Class<T> type)
      Creates a new optional of the specified type, recursively populated with random values
      static Fixture fixture()
      Creates a new Fixture with default configuration:
    • Constructor Detail

      • Fixture

        public Fixture()
        Creates a new Fixture with default configuration:

        • maxCollectionSize = 10
        • minCollectionSize = 2
        • streamSize = 3
        • usePositiveNumbersOnly = false
        • clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)

      • Fixture

        public Fixture​(Configuration configuration)
        Creates a new Fixture with given configuration
        Parameters:
        configuration - the configuration
    • Method Detail

      • fixture

        public static Fixture fixture()
        Creates a new Fixture with default configuration:

        • maxCollectionSize = 10
        • minCollectionSize = 2
        • streamSize = 3
        • usePositiveNumbersOnly = false
        • clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)

      • configuration

        public static Configuration configuration()
        Returns a new default configuration with the following values

        • maxCollectionSize = 10
        • minCollectionSize = 2
        • streamSize = 3
        • usePositiveNumbersOnly = false
        • clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)

        Returns:
        Configuration
      • create

        public <T> T create​(Class<T> type)
        Creates a new object of the specified type, recursively populated with random values
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the Class<T> based on which the object is created
        Returns:
        a new object of the specified Class<T>
      • createOptional

        public <T> Optional<T> createOptional​(Class<T> type)
        Creates a new optional of the specified type, recursively populated with random values
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the Class<T> based on which the object is created
        Returns:
        a new Optional of the specified Class<T>
      • create

        public <T> T create​(SpecimenType<T> type)
        Creates a new object of the specified type, recursively populated with random values
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the SpecimenType<T> based on which the object is created
        Returns:
        a new object of the specified type T
      • construct

        public <T> T construct​(Class<T> type)
        Creates a new object of the specified type, using a random constructor if available
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the Class<T> based on which the object is created
        Returns:
        a new object of the specified type T
      • construct

        public <T> T construct​(SpecimenType<T> type)
        Creates a new object of the specified type, using a random constructor if available
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the SpecimenType<T> based on which the object is created
        Returns:
        a new object of the specified type T
      • createMany

        public <T> Stream<T> createMany​(Class<T> type)
        Creates a Stream of objects of the specified type, recursively populated with random values
        Type Parameters:
        T - the type of the objects to be created
        Parameters:
        type - the Class<T> based on which the objects are created
        Returns:
        a Stream of objects of the specified type T
      • createMany

        public <T> Stream<T> createMany​(SpecimenType<T> type)
        Creates a Stream of objects of the specified type, recursively populated with random values
        Type Parameters:
        T - the type of the objects to be created
        Parameters:
        type - the SpecimenType<T> based on which the objects are created
        Returns:
        a Stream of objects of the specified type T
      • build

        public <T> ISpecimenBuilder<T> build​(Class<T> type)
        Creates a ISpecimenBuilder<T> to customise the object of type T to be created
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the Class<T> based on which the object is created
        Returns:
        a builder for further customisation
      • build

        public <T> ISpecimenBuilder<T> build​(SpecimenType<T> type)
        Creates a ISpecimenBuilder<T> to customise the object of type T to be created
        Type Parameters:
        T - the type of the object to be created
        Parameters:
        type - the SpecimenType<T> based on which the object is created
        Returns:
        a builder for further customisation
      • addManyTo

        public <T> void addManyTo​(Collection<T> result,
                                  Class<T> type)
        Adds objects of the specified Class<T>, recursively populated with random values, to the specified Collection<T> The number of objects created is specified in the Configuration under streamSize (default: 3)
        Type Parameters:
        T - the type of the collection and the objects to be added
        Parameters:
        result - the collection the created objects should be added to
        type - the Class<T> based on which the objects are created
      • addManyTo

        public <T> void addManyTo​(Collection<T> result,
                                  SpecimenType<T> type)
        Adds objects of the specified SpecimenType<T>, recursively populated with random values, to the specified Collection<T> The number of objects created is specified in the Configuration under streamSize (default: 3)
        Type Parameters:
        T - the type of the collection and the objects to be added
        Parameters:
        result - the collection the created objects should be added to
        type - the SpecimenType<T> based on which the objects are created