nz.ac.waikato.modeljunit.examples
Class SmartSetAdaptor

java.lang.Object
  extended by nz.ac.waikato.modeljunit.examples.SimpleSet
      extended by nz.ac.waikato.modeljunit.examples.SmartSetAdaptor
All Implemented Interfaces:
FsmModel

public class SmartSetAdaptor
extends SimpleSet

This class shows how we can use inheritance to add adaptor code. That is, it subclasses the SimpleSet model and adds adaptor code that links the model to a system under test (SUT).

It does a little more than just this, because I decided that I wanted to test a set with more than 12 elements (to force HashSet to expand at least once). So in this adaptor class, the s1 flag models the presence/absence of the empty string "", while the s2 flag models the presence/absence of TWELVE other strings "s1".."s12". This means that those strings are always added or deleted as a group, so our model stays small (4 states and 16 transitions) so is easy and quick to test thoroughly. This is an example of abstraction -- where the model takes a simplified view (the s2 boolean) of a more complex situation in the SUT (twelve strings).


Field Summary
protected  int S2_STRINGS
           
protected  java.util.Set<java.lang.String> sut_
           
 
Fields inherited from class nz.ac.waikato.modeljunit.examples.SimpleSet
s1, s2
 
Constructor Summary
SmartSetAdaptor(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.
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 nz.ac.waikato.modeljunit.examples.SimpleSet
getState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

S2_STRINGS

protected final int S2_STRINGS
See Also:
Constant Field Values

sut_

protected java.util.Set<java.lang.String> sut_
Constructor Detail

SmartSetAdaptor

public SmartSetAdaptor(java.util.Set<java.lang.String> sut)
Method Detail

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
Overrides:
reset in class SimpleSet
Parameters:
testing - true means the SUT should be reset too.

addS1

public void addS1()
Overrides:
addS1 in class SimpleSet

addS2

public void addS2()
Overrides:
addS2 in class SimpleSet

removeS1

public void removeS1()
Overrides:
removeS1 in class SimpleSet

removeS2

public void removeS2()
Overrides:
removeS2 in class SimpleSet

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. This method would typically be written as a JUnit test method, but we write it as main so that it is easy to run.



Copyright © 2009 ModelJUnit Project. All Rights Reserved.