Concepts
On This Page
Before you learn about the options Fixture Monkey provides, there are a few things you need to know.
Property
In the documentation, the term property
is consistently used instead of field
when referring to the characteristics of a class’s object.
While it has the same name as ‘property’ in Kotlin, the concept is different in Fixture Monkey.
Fixture Monkey’s initial structure was primarily based on fields, which imposed limitations on configuration and control through methods and other mechanisms.
For example, when relying solely on fields, it’s not possible to access annotations on setter methods.
To address this limitation, the Property
interface was introduced, which extends support beyond just fields.
A property
in Fixture Monkey, functions as a fundamental component within a class and can represent a Field
, Method
, or Kotlin Property
.
It contains information about its Type
, Annotation
s on it, and its name
.
Moreover, in Fixture Monkey, the characteristics of both Objects
and Containers
are also expressed through the concept of property
.
ObjectProperty
An ObjectProperty
is a property that represents immutable object information. It includes:
- property: The property of the object itself.
- propertyNameResolver: Determines how the property name is resolved.
- nullInject: The probability of injecting null value.
- elementIndex: If the object is an element of a Container, it indicates the index.
- childPropertyListsByCandidateProperty: A map that holds information about child properties grouped by candidate property.
public final class ObjectProperty {
private final Property property;
private final PropertyNameResolver propertyNameResolver;
private final double nullInject;
@Nullable
private final Integer elementIndex;
private final Map<Property, List<Property>> childPropertyListsByCandidateProperty;
}
ContainerProperty
The property of a container type is represented by ContainerProperty
, which describes immutable container information. It includes:
- elementProperties: A list of element properties.
- containerInfo: The
ArbitraryContainerInfo
that determines the container’s size.
public final class ContainerProperty {
private final List<Property> elementProperties;
private final ArbitraryContainerInfo containerInfo;
}
Options
In Fixture Monkey, several options share common characteristics.
For example, let’s take a look at the options related to modifying the ObjectPropertyGenerator
defaultObjectPropertyGenerator
,pushObjectPropertyGenerator
,pushAssignableTypeObjectPropertyGenerator
,pushExactTypeObjectPropertyGenerator
Options with the prefix default are applied as defaults to all properties generated by Fixture Monkey. These defaults set a basic behavior that affects all property types uniformly.
However, if you need to apply specific options for a particular type, you can make use of the options that start with push. There are three variations of these push options.
push~
: Accepts a MatcherOperator as a parameter.pushAssignableType~
: This option applies the specified setting to every property type for which the given type (associated with the option) is assignable. This means that the option is applied not only to the exact given type but also to any type that can be assigned to the property type, including superclasses or superinterfaces.pushExactType~
: This option limits the setting to properties with the exact same type. It does not impact properties with subtype or supertype relationships.
It’s important to note that options set using the push
variants take precedence over the default
options. This means that when a push
option is defined for a specific type, it will override any corresponding default
option for that type.