org.unitils.mock.report.impl
Class ProxyInvocationsReport

java.lang.Object
  extended by org.unitils.mock.report.impl.ProxyInvocationsReport
Direct Known Subclasses:
ObservedInvocationsReport

public abstract class ProxyInvocationsReport
extends Object

A base class for reports about proxy invocations.

Author:
Tim Ducheyne, Filip Neven, Kenny Claes

Nested Class Summary
protected static class ProxyInvocationsReport.FormattedObject
          Class for representing a value that was too large to be displayed inline.
 
Field Summary
static int MAX_INLINE_PARAMETER_LENGTH
          The maximum length of an inline value
static int OBJECT_FORMATTER_MAX_NR_ARRAY_OR_COLLECTION_ELEMENTS
          The maximum nr of elements for arrays and collections to display in the reports
static int OBJECT_FORMATTER_MAX_RECURSION_DEPT
          The maximum depth (child objects) of objects to display in the reports.
protected  ObjectFormatter objectFormatter
           
protected  Map<Object,String> testedObjectFieldValuesAndNames
           
 
Constructor Summary
ProxyInvocationsReport(Object testedObject)
           
 
Method Summary
protected  String createLargeValueName(Class<?> type, Map<Class<?>,Integer> largeObjectNameIndexes)
          Creates a name to replace a large value.
protected  String formatInvocationIndex(int invocationIndex, int totalInvocationNumber)
          Formats the invocation number, and adds spaces to make sure everything is formatted nicely on the same line width.
protected  String formatInvokedAt(ProxyInvocation proxyInvocation)
          Creates a string representation of the details of the given invocation.
protected  String formatObject(Object object)
           
protected  String formatValue(Object valueAtInvocationTime, Object value, Class<?> type, List<ProxyInvocationsReport.FormattedObject> currentLargeObjects, Map<Object,ProxyInvocationsReport.FormattedObject> allLargeObjects, Map<Class<?>,Integer> largeObjectNameIndexes)
          Formats the given value.
protected  Map<Object,String> getFieldValuesAndNames(Object testedObject)
          Gets all the field values in the given test object with their corresponding field names.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OBJECT_FORMATTER_MAX_RECURSION_DEPT

public static int OBJECT_FORMATTER_MAX_RECURSION_DEPT
The maximum depth (child objects) of objects to display in the reports.


OBJECT_FORMATTER_MAX_NR_ARRAY_OR_COLLECTION_ELEMENTS

public static int OBJECT_FORMATTER_MAX_NR_ARRAY_OR_COLLECTION_ELEMENTS
The maximum nr of elements for arrays and collections to display in the reports


MAX_INLINE_PARAMETER_LENGTH

public static int MAX_INLINE_PARAMETER_LENGTH
The maximum length of an inline value


objectFormatter

protected ObjectFormatter objectFormatter

testedObjectFieldValuesAndNames

protected Map<Object,String> testedObjectFieldValuesAndNames
Constructor Detail

ProxyInvocationsReport

public ProxyInvocationsReport(Object testedObject)
Method Detail

formatInvokedAt

protected String formatInvokedAt(ProxyInvocation proxyInvocation)
Creates a string representation of the details of the given invocation. This will give information about where the invocation occurred.

Parameters:
proxyInvocation - The invocation to format, not null
Returns:
The string representation, not null

formatValue

protected String formatValue(Object valueAtInvocationTime,
                             Object value,
                             Class<?> type,
                             List<ProxyInvocationsReport.FormattedObject> currentLargeObjects,
                             Map<Object,ProxyInvocationsReport.FormattedObject> allLargeObjects,
                             Map<Class<?>,Integer> largeObjectNameIndexes)
Formats the given value. If the value is small enough (lenght <=20), the value itself is returned, else a name is returned generated by the createLargeValueName(java.lang.Class, java.util.Map, java.lang.Integer>) method.

E.g. string1, myClass1

Parameters:
valueAtInvocationTime - The value to format, not null
value - The value to format by reference, not null
type - The type of the large value, not null
currentLargeObjects - The current the large values, not null
allLargeObjects - All large values per value, not null
largeObjectNameIndexes - The current indexes to use for the large value names (per value type), not null
Returns:
The value or the replaced name, not null

createLargeValueName

protected String createLargeValueName(Class<?> type,
                                      Map<Class<?>,Integer> largeObjectNameIndexes)
Creates a name to replace a large value. The name is derived from the given type and index. E.g. string1, myClass1

Parameters:
type - The type of the large value, not null
largeObjectNameIndexes - The current indexes per type, not null
Returns:
The name, not null

formatInvocationIndex

protected String formatInvocationIndex(int invocationIndex,
                                       int totalInvocationNumber)
Formats the invocation number, and adds spaces to make sure everything is formatted nicely on the same line width.

Parameters:
invocationIndex - The index of the invcation
totalInvocationNumber - The total number of invocations.
Returns:
The formatted invocation number

formatObject

protected String formatObject(Object object)
Parameters:
object - The object
Returns:
A string representation of the object, not null

getFieldValuesAndNames

protected Map<Object,String> getFieldValuesAndNames(Object testedObject)
Gets all the field values in the given test object with their corresponding field names.

Parameters:
testedObject - The test object
Returns:
The values and names in an identity map, empty if tested object is null


Copyright © 2011. All Rights Reserved.