|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jwalk.core.ValueGenerator org.jwalk.core.ArrayGenerator org.jwalk.core.ObjectGenerator
public class ObjectGenerator
ObjectGenerator is the standard generator of object, array and basic values.
Since Generators can be quite complicated, the standard ObjectGenerator is
split into three parts, with ValueGenerator being the root of a hierarchy,
whose descendants are ArrayGenerator and finally ObjectGenerator.
ObjectGenerator is able to synthesise values of most Java types, including
value-types, array-types and object-types. ObjectGenerator is the first
concrete generator to completely satisfy the interface of MasterGenerator.
It is the default generator used by every JWalker.
Locally, ObjectGenerator is able to synthesise values of any class which
has public constructors and is not abstract. It inherits the ability to
synthesise array values from ArrayGenerator; and simple values from
ValueGenerator. Other custom generators may be added to an ObjectGenerator
when it is created. A standard set of custom generators is loaded by the
JWalker's Settings (and are configurable by the tester). These provide the
following capabilities:
Through its delegate StringGenerator, ObjectGenerator also provides the
ability to synthesise 26 conventional strings in alphabetical order.
Through its delegate InterfaceGenerator, ObjectGenerator also provides the
ability to synthesise concrete values for certain interfaces (in an ad-hoc
manner).
Through its delegate EnumGenerator, ObjectGenerator also provides the
ability to synthesise values of enumerated types.
Through its delegate PlatformGenerator, ObjectGenerator also provides the
ability to synthesise values of the Date, Locale and Charset types.
Field Summary | |
---|---|
protected java.util.Map<java.lang.Class<?>,java.lang.Integer> |
indexMap
The bag counting the created instances of each class |
protected java.util.Map<java.lang.Object,java.lang.String> |
oracleMap
The log mapping from object addresses to oracle values |
protected java.lang.Object |
target
The target object, the instance of the test class, which we may need to return as a value in response to a request for a binary method argument. |
protected java.lang.Class<?> |
targetType
The target type we need to retain, in case of needing to synthesise values for binary methods. |
protected JWalker |
walker
The JWalker which created this Generator. |
Fields inherited from class org.jwalk.core.ValueGenerator |
---|
delegates |
Constructor Summary | |
---|---|
ObjectGenerator(JWalker walker)
Creates an ObjectGenerator. |
Method Summary | |
---|---|
boolean |
canCreate(java.lang.Class<?> type)
Reports whether this ObjectGenerator synthesises objects of a given type. |
protected java.lang.Object |
createClass(java.lang.Class<?> type)
Returns an instance of any metaclass type "Class>T<". |
protected java.lang.Object |
createFromNextConstructor(java.lang.Class<?> type)
Tries all the constructors of a type until one of them succeeds. |
protected java.lang.Object |
createObject(java.lang.Class<?> type)
Creates the next instance of a general object-type. |
JWalker |
getJWalker()
Returns the JWalker which created this ObjectGenerator. |
java.lang.Object |
getTarget()
Returns the target object, if this has already been logged. |
java.lang.Class<?> |
getTargetType()
Returns the type of the target object. |
protected boolean |
isMetaClass(java.lang.Class<?> type)
Reports if a type is any metaclass type "Class>T<". |
void |
logObject(java.lang.Object object)
Registers a synthesised object with this ObjectGenerator. |
void |
logTarget(java.lang.Object object)
Registers the target object with this ObjectGenerator. |
java.lang.Object |
nextValue(java.lang.Class<?> type)
Creates the next quasi-unique value in sequence for a particular type. |
java.lang.String |
oracleValue(java.lang.Object object)
Converts an object into its oracle value format. |
Methods inherited from class org.jwalk.core.ArrayGenerator |
---|
createArray, isArray, isPrintable |
Methods inherited from class org.jwalk.core.ValueGenerator |
---|
addDelegate, createPrimitive, createWrapped, isEnumerated, isPrimitive, isWrapped |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected JWalker walker
protected java.lang.Class<?> targetType
protected java.lang.Object target
protected java.util.Map<java.lang.Object,java.lang.String> oracleMap
protected java.util.Map<java.lang.Class<?>,java.lang.Integer> indexMap
Constructor Detail |
---|
public ObjectGenerator(JWalker walker)
Method Detail |
---|
public boolean canCreate(java.lang.Class<?> type)
boolean canCreate(Class)
. In principle, ObjectGenerator
can synthesise every type. However, this is only an approximation,
since third-party software may contain unknown interfaces and abstract
classes, for which custom generators must be supplied.
type
- the requested type.
protected boolean isMetaClass(java.lang.Class<?> type)
type
- the type to inspect.
Class.class
.protected java.lang.Object createClass(java.lang.Class<?> type)
type
- the requested metaclass type.
protected java.lang.Object createFromNextConstructor(java.lang.Class<?> type) throws GeneratorException
nextValue(type)
recursively.
type
- the requested type.
GeneratorException,
- if none of the constructors for the type
eventually succeed; or if a SecurityManager refuses to grant access
to the type's constructors.
GeneratorException
protected java.lang.Object createObject(java.lang.Class<?> type) throws GeneratorException
type
- the requested type.
GeneratorException,
- if no object of this type could be
synthesised.
GeneratorException
public java.lang.Object nextValue(java.lang.Class<?> type) throws GeneratorException
Object nextValue(Class)
. If the requested type is the
same as the type of the target, the first value returned will be the
target object (assuming this exists) and subsequent instances will be
different objects. In general, this ObjectGenerator checks first
whether the requested type is handled by one of the CustomGenerators
that were added as delegates, using this in preference to local
algorithms. Otherwise, analyses the requested type and synthesises an
instance of the type using one of the algorithms:
createPrimitive(type)
,
createWrapped(type)
,
createArray(type)
, or
createObject(type)
.
Standard delegate CustomGenerators include: StringGenerator,
EnumGenerator, InterfaceGenerator and PlatformGenerator.
type
- the requested type.
GeneratorException,
- if no object of this type could be
synthesised; or if one of the custom generators failed.
GeneratorException
- if no value of this type could be
synthesised.public void logTarget(java.lang.Object object)
object
- the target object.public java.lang.Object getTarget()
public java.lang.Class<?> getTargetType()
public JWalker getJWalker()
public void logObject(java.lang.Object object)
object
- the object to be logged.public java.lang.String oracleValue(java.lang.Object object)
oracleValue
in interface MasterGenerator
oracleValue
in class ArrayGenerator
object
- an object synthesised by this ObjectGenerator.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |