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>
-
-
Field Summary
-
Fields inherited from class net.andreinc.mockneat.abstraction.MockUnitBase
mockNeat
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Reflect<T>field(java.lang.String fieldName, java.lang.Object value)Associates the class field with a constant value.<T1> Reflect<T>field(java.lang.String fieldName, MockUnit<T1> mockUnit)Associates the class field with a givenMockUnit<T>when generating values.static <T> Reflect<T>reflect(java.lang.Class<T> cls)Returns a newReflect<T>object that can be used to fill-up objects through reflectionjava.util.function.Supplier<T>supplier()This is the sole abstract method of the interface.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 usingfield(String, Object)<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 usingfield(String, MockUnit)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:-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.andreinc.mockneat.abstraction.MockUnit
array, array, collection, collection, collection, collection, collection, collection, consume, consume, get, get, list, list, list, list, list, list, map, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapKeys, mapToDouble, mapToInt, mapToLocalDate, mapToLong, mapToString, mapToString, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, mapVals, serialize, set, set, set, set, set, set, stream, val, val, valStr, valStr
-
-
-
-
Method Detail
-
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 reflectionCheck
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 implementsMockUnit<T>
-
supplier
public java.util.function.Supplier<T> supplier()
Description copied from interface:MockUnitThis is the sole abstract method of the interface. Needs to be implemented every-time a MockUnit is implemented.
-
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 eithertrueorfalseCharacter/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) rangeShort/short- the default value is a short number in the [0, 100) rangeString- 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 fieldvalue- 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 fieldmockUnit- The unit used to generate the arbitrary value- Returns:
- The same
Reflect<T>object.
-
-