nz.ac.waikato.modeljunit.examples
Class SimpleSetWithAdaptor
java.lang.Object
nz.ac.waikato.modeljunit.examples.SimpleSetWithAdaptor
- All Implemented Interfaces:
- FsmModel
public class SimpleSetWithAdaptor
- extends java.lang.Object
- implements FsmModel
A model of a set with two elements: s1 and s2.
This model includes the adaptor/harness code that interacts with a
system under test (SUT), which can be any implementation of Set.
The SUT must be passed to the constructor of this class.
After each transition, we call checkSUT(), which uses JUnit Assert
methods to check that the SUT is in the expected state.
(To see a test fail, either pass an instance of StringSetBuggy
to the constructor, or change the "false" in removeS2 to "true").
Note: We could have added this adaptor code by inheriting from the
SimpleSet model, but in this example the model code and the
adaptor code are written in the same class, so that you can see
them side-by-side.
Field Summary |
protected boolean |
s1
|
protected boolean |
s2
|
protected java.lang.String |
str1
|
protected java.lang.String |
str2
|
protected java.util.Set<java.lang.String> |
sut_
|
Method Summary |
void |
addS1()
|
void |
addS2()
|
protected void |
checkSUT()
Check that the SUT is in the expected state. |
java.lang.Object |
getState()
Return the current state of the FSM model. |
static void |
main(java.lang.String[] args)
An example of generating tests from this model. |
void |
removeS1()
|
void |
removeS2()
|
void |
reset(boolean testing)
Reset the model to its initial state. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
sut_
protected java.util.Set<java.lang.String> sut_
s1
protected boolean s1
s2
protected boolean s2
str1
protected java.lang.String str1
str2
protected java.lang.String str2
SimpleSetWithAdaptor
public SimpleSetWithAdaptor()
- Tests a StringSet implementation.
SimpleSetWithAdaptor
public SimpleSetWithAdaptor(java.util.Set<java.lang.String> sut)
getState
public java.lang.Object getState()
- Description copied from interface:
FsmModel
- Return the current state of the FSM model.
The objects returned by this method define the states
(the nodes) of the finite state machine. The objects that
are returned must have a correct implementation of the equals
method, since this is used to decide whether two states are
the same or not. It is common to return a string, but
other kinds of objects can be used if desired (in which case,
their toString() method will be used to get a printable form
of each FSM state).
Advanced Feature: This method can be used to define
equivalence classes over the states, if you want to reduce
the number of states to keep the FSM small.
For example, if you have a integer state variable I that can
have a huge number of possible values, you could define your
getState() method to return new Integer(I % 10)
.
This would reduce the FSM to just 10 states, where FSM state 0
represents all the states where I=0 or I=10 or I=20 etc., and
FSM state 1 represents all the states where I=1 or I=11 or I=21 etc.
- Specified by:
getState
in interface FsmModel
- Returns:
- An object that represents the current state.
reset
public void reset(boolean testing)
- Description copied from interface:
FsmModel
- Reset the model to its initial state.
If the testing parameter is true, then this reset and all the
following actions should affect the SUT.
- Specified by:
reset
in interface FsmModel
- Parameters:
testing
- true means the SUT should be reset too.
addS1
public void addS1()
addS2
public void addS2()
removeS1
public void removeS1()
removeS2
public void removeS2()
checkSUT
protected void checkSUT()
- Check that the SUT is in the expected state.
main
public static void main(java.lang.String[] args)
- An example of generating tests from this model.
Copyright © 2009 ModelJUnit Project. All Rights Reserved.