Skip to content

Default Behaviour

Richard Keenan edited this page Apr 3, 2015 · 3 revisions

Default Supported Types

The following is a table outlining the default behaviour of JFixture. This applies if no customisations or custom builders have been added to the JFixture instance.

Data Type Value/s
Boolean Alternate between TRUE and FALSE
Number* Random integer; range from [1-127], then [128-32766], etc
String UUID**
UUID UUID
Character Random; 'a'-'z'
Date Random; now +-2 years
Calendar Gregorian, random date; now +-2 years
Primitives Boxed equivilant
Array Populated array***
Iterable, List Populated ArrayList***
Map Populated HashMap***
Set Populated HashSet***
Queue Populated ArrayDeque***
Enum Shuffles values and cycles through them
Type/Class Invokes smallest constructor
Abstract Class/Interface Undefined****

*Supported Numbers are Byte, Short, Integer, Long, Float, Double, BigDecimal, BigInteger and their primitive versions where applicable

**Prefixed with field/property name where applicable

***All collection type objects are populated with 3 items by default

****For abstract classes/interfaces not covered by the default behaviour a SubTypeCustomisation could be used.

Default Creation Methods

This is process involved in creating a type

  1. Construct instance of requested type
    1. Priority given to constructors, ordered by ascending parameter count
    2. If that fails look for factory methods (public, static methods with return type assignable to declaring type), ordered by ascending parameter count
  2. Create instances of all parameter types
  3. Invoke construction method (constructor or factory method) with parameters values
  4. Find all settable properties (getter, setter pairs with one argument in the setter)
    1. Create instance of parameter type
    2. Call the setter with the parameter instance
    3. Repeat for all settable properties
  5. Find all settable fields (public, non-final, non-static)
    1. Create instance of field type
    2. Invoke set method on the field with the parameter instance
    3. Repeat for all settable fields
  6. Return object

If a recursive call (Type Foo has property Bar which has property Foo) is identified JFixture will throw an exception with a detailed error message explaining which type caused the problem. You should redesign your classes to remove the cyclic dependency, or customise JFixture to prevent it resolving the problem area.

Clone this wiki locally