Class Reflect<T>

java.lang.Object
net.andreinc.mockneat.abstraction.MockUnitBase
net.andreinc.mockneat.unit.objects.Reflect<T>
All Implemented Interfaces:
MockUnit<T>

public class Reflect<T>
extends MockUnitBase
implements MockUnit<T>
  • Constructor Details

    • Reflect

      protected Reflect​(java.lang.Class<T> cls)
    • Reflect

      public Reflect​(MockNeat mockNeat, java.lang.Class<T> cls)
  • Method Details

    • reflect

      public static <T> Reflect<T> reflect​(java.lang.Class<T> cls)

      Returns a new Reflect<T> object that can be used to fill-up objects through reflection

      Check filler(Supplier<T>) as an alternative that doesn't use reflection.

      Type Parameters:
      T - The generic type of the class
      Parameters:
      cls - The type of the class you want to construct
      Returns:
      A re-usable Reflect<T> instance. The class implements MockUnit<T>
    • supplier

      public java.util.function.Supplier<T> supplier()
      Description copied from interface: MockUnit
      This is the sole abstract method of the interface. Needs to be implemented every-time a MockUnit is implemented.
      Specified by:
      supplier in interface MockUnit<T>
      Returns:
      A Supplier<T>.
    • field

      public <T1> Reflect<T> field​(java.lang.String fieldName, MockUnit<T1> mockUnit)

      Associates the class field with a given MockUnit<T> when generating values.

      Field can be private by not final.

      Type Parameters:
      T1 - the type fo the mock unit used.
      Parameters:
      fieldName - The field name (not the setter name!)
      mockUnit - The unit that generates values for the field
      Returns:
      The same Reflect<T> object.
    • field

      public Reflect<T> field​(java.lang.String fieldName, java.lang.Object value)

      Associates the class field with a constant value.

      Field can be private by not final.

      Parameters:
      fieldName - The field name (not the setter name!)
      value - The constant value the field will have
      Returns:
      The same Reflect<T> object
    • useDefaults

      public Reflect<T> useDefaults​(boolean status)

      If the field is not specified, you can enable the library to use default values for a limited range of common types:

      • Boolean/boolean - the default value is either true or false
      • Character/char - the default value is an arbitrary letter.
      • Double/double - the default value is an arbitrary double in the range [0.0, 10.0)
      • Float/float - the default value is an arbitrary float in the range [0,0, 10.0)
      • Integer/int - the default value is an arbitrary int number in the [0, 100) range
      • Short/short - the default value is a short number in the [0, 100) range
      • String - a random string with a size of 32

      By default the defaults are disabled

      Parameters:
      status - true to enable, false otherwise.
      Returns:
      The same Reflect<T> object
    • type

      public Reflect<T> type​(java.lang.Class<?> cls, java.lang.Object value)

      Adds a default constant value for a type when the field is not defined using field(String, Object)

      This definition will be used only if the default values where activated with useDefaults(boolean)

      Can be used to override default values.

      Parameters:
      cls - The type of the field
      value - THe constant value
      Returns:
      The same Reflect<T> object.
    • type

      public <T1> Reflect<T> type​(java.lang.Class<T1> cls, MockUnit<T1> mockUnit)

      Adds a default mock unit for a type when the field is not defined using field(String, MockUnit)

      This definition will be used only if the default values where activated with useDefaults(boolean)

      Can be used to override default values.

      Type Parameters:
      T1 - The MockUnit type
      Parameters:
      cls - The type of the field
      mockUnit - The unit used to generate the arbitrary value
      Returns:
      The same Reflect<T> object.