org.jwalk.out
Class StateReport

java.lang.Object
  extended by org.jwalk.out.Report
      extended by org.jwalk.out.ProtocolReport
          extended by org.jwalk.out.StateReport

public class StateReport
extends ProtocolReport

StateReport is a report on the test class's high-level design states. A StateReport is responsible for formatting the data generated by a StateSpaceWalker, which estimated the high-level design states of the test class. It also provides direct access to the test class and its constructors and methods, optionally offering a subset of methods which are state predicates. It also provides access to the names of the discovered states, the state cover (the test sequences that reach every state) and the maximum number of high-level states, estimated from the nubmer of independent state predicates.

Version:
1.0
Author:
Anthony Simons

Field Summary
 
Fields inherited from class org.jwalk.out.Report
edition, walker
 
Constructor Summary
StateReport(StateSpaceWalker walker)
          Creates a StateReport.
 
Method Summary
protected  java.lang.String banner()
          Creates a text banner to use at the start of the report.
 int countMaxStates()
          Counts the maximum possible number of high-level design states.
 java.lang.String getContent()
          Returns the content of this StateSpaceReport as formatted text.
 StateSpaceWalker getJWalker()
          Return the StateSpaceWalker which was the source of this report.
 java.util.Map<java.lang.String,TestSequence> getStateCover()
          Returns the map from state names to state cover sequences.
 java.util.List<java.lang.String> getStateNames()
          Returns a list of the names of the discovered states.
 java.util.List<java.lang.reflect.Method> getStatePredicates()
          Returns a list of the state predicates of the test class.
 boolean hasMissingStates()
          Reports if there are still missing states after state exploration.
protected  java.lang.String toString(TestSequence sequence)
          Returns a formatted version of a TestSequence.
 
Methods inherited from class org.jwalk.out.ProtocolReport
getConstants, getConstructors, getMethods, getTestClass, isAbstract, toString, toString, toString
 
Methods inherited from class org.jwalk.out.Report
getEdition, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StateReport

public StateReport(StateSpaceWalker walker)
Creates a StateReport. Extracts all the report data from a walker which must be (at least) a StateSpaceWalker which explored the high-level design states of the test class.

Parameters:
walker - the StateSpaceWalker used to explore the test class.
Method Detail

getJWalker

public StateSpaceWalker getJWalker()
Return the StateSpaceWalker which was the source of this report. This method narrows the return type from JWalker to StateSpaceWalker.

Overrides:
getJWalker in class ProtocolReport
Returns:
the StateSpaceWalker which dispatched this report.

getStateCover

public java.util.Map<java.lang.String,TestSequence> getStateCover()
Returns the map from state names to state cover sequences. The state cover sequences are the shortest TestSequences that reached the named states. Each sequence has been executed, so may be printed.

Returns:
the map from state names to state cover sequences.

getStateNames

public java.util.List<java.lang.String> getStateNames()
Returns a list of the names of the discovered states. These are the names synthesised by the StateSpaceWalker, which are based on the names of the state predicate methods that hold in this state. For example, a pair of predicates isOnLoan() and isReserved() will give rise to states called: "OnLoan", "Reserved" and "OnLoan&Reserved". The state where no predicates hold is called "Default". These state names are used as keys in the state cover map.

Returns:
a list of the names of the discovered states.

getStatePredicates

public java.util.List<java.lang.reflect.Method> getStatePredicates()
Returns a list of the state predicates of the test class.

Returns:
a list of state predicates.

countMaxStates

public int countMaxStates()
Counts the maximum possible number of high-level design states. This is based on the number of state predicates in the test class. If there are none, there is one "Default" state. If there are n state predicates, there are 2^n possible states. In practice, there may be fewer actual states, if the state predicates are not mutually independent.

Returns:
the maximum number of high-level design states.

hasMissingStates

public boolean hasMissingStates()
Reports if there are still missing states after state exploration.

Returns:
true if more states were expected, but not found.

toString

protected java.lang.String toString(TestSequence sequence)
Returns a formatted version of a TestSequence. Used when printing out the state cover, this method breaks long TestSequences over several lines, with suitable indentation.

Parameters:
sequence - the TestSequence to format
Returns:
a formatted version of the TestSequence.

banner

protected java.lang.String banner()
Creates a text banner to use at the start of the report. This is sensitive to whether the test class was a public class, an abstract class, or an interface.

Overrides:
banner in class ProtocolReport

getContent

public java.lang.String getContent()
Returns the content of this StateSpaceReport as formatted text. The returned text has a banner announcing the state space, then on each line, a state name and the state cover sequence. If it is clear that not every state was discovered, a further note to this effect appears last. Warns if memory was exhausted and if state predicates are not independent. This method implements toString() for StateReport.

Overrides:
getContent in class ProtocolReport
Returns:
a formatted textual report.