net.sf.qualitytest.blueprint
Class Blueprint

java.lang.Object
  extended by net.sf.qualitytest.blueprint.Blueprint

public final class Blueprint
extends Object

Blueprinting is a technique that makes writing test easier. For unit-testing you often need data-objects, where the actual content of the objects does not matter. Blueprint creates data-objects filled with random or defined data automatically based on the "Blue-Print" which is the Class itself.

Blueprinting makes tests more maintainable as they depend less on test-data. Imagine, you add a new required attribute to a class. Usually, you have to add this to all tests using this class. With blueprinting you just have to add it to certain tests where the contents of the logic does actually matter. Most of the time the randomly generated value by Blueprint is just fine.

Blueprint is similar to C#'s AutoFixture (https://github.com/AutoFixture/AutoFixture#readme).

A simple example:

 final BlueprintConfiguration config = new RandomBlueprintConfiguration().with("email", "mail@example.com");
 final User user = Blueprint.construct(User.class, config);
 
or simpler
 final User user = Blueprint.random().with("email", "mail@example.com").construct(User.class);
 
Blueprint offers two custom configurations. A DefaultBlueprintConfiguration which fills any object using default, empty or 0 values. The second configuration, RandomBlueprintConfiguration will always generate a random value. Both fill child objects using a deep-tree-search.

Utilities for collections can be found in CollectionBlueprint.

Author:
Dominik Seichter
See Also:
DefaultBlueprintConfiguration, RandomBlueprintConfiguration

Method Summary
static
<T> T
construct(Class<T> clazz)
          Construct a Java-Object using a class as a blueprint.
static
<T> T
construct(Class<T> clazz, BlueprintConfiguration config)
          Construct a Java-Object using a class as a blueprint.
static
<T> T
construct(Class<T> clazz, BlueprintConfiguration config, BlueprintSession session)
          Construct a Java-Object using a class as a blueprint.
static BlueprintConfiguration def()
          Return a new configuration for default blueprinting with zero or empty default values.
protected static boolean isRelevant(Method m)
          Check if a method is setter according to the java
static BlueprintConfiguration random()
          Return a new configuration for random blueprinting.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

construct

@Nullable
public static <T> T construct(@Nonnull
                                       Class<T> clazz)
Construct a Java-Object using a class as a blueprint. If the object has a default constructor, it will be called and all setters will be called. If the object does not have a default constructor the first constructor is called and filled with all parameters. Afterwards all setters will be called.

Type Parameters:
T -
Parameters:
clazz - a class
Returns:
a blue printed instance of T

construct

@Nullable
public static <T> T construct(@Nonnull
                                       Class<T> clazz,
                                       @Nonnull
                                       BlueprintConfiguration config)
Construct a Java-Object using a class as a blueprint. If the object has a default constructor, it will be called and all setters will be called. If the object does not have a default constructor the first constructor is called and filled with all parameters. Afterwards all setters will be called.

Type Parameters:
T -
Parameters:
clazz - a class
config - a BlueprintConfiguration
Returns:
a blue printed instance of T

construct

@Nullable
public static <T> T construct(@Nonnull
                                       Class<T> clazz,
                                       @Nonnull
                                       BlueprintConfiguration config,
                                       @Nonnull
                                       BlueprintSession session)
Construct a Java-Object using a class as a blueprint. If the object has a default constructor, it will be called and all setters will be called. If the object does not have a default constructor the first constructor is called and filled with all parameters. Afterwards all setters will be called.

Type Parameters:
T -
Parameters:
clazz - a class
config - a BlueprintConfiguration
session - a BlueprintSession
Returns:
a blue printed instance of T

def

public static BlueprintConfiguration def()
Return a new configuration for default blueprinting with zero or empty default values.

Returns:
a new DefaultBlueprintConfiguration

isRelevant

protected static boolean isRelevant(Method m)
Check if a method is setter according to the java

Parameters:
m - a method
Returns:
true if this is a setter method

random

public static BlueprintConfiguration random()
Return a new configuration for random blueprinting.

Returns:
a new RandomBlueprintConfiguration


Copyright © 2012-2013. All Rights Reserved.