Hi,
We have the following method that we need to test ( see code snippet).
I know about junit ( using 4 here) and Jmock, but all hints are
welcome.
How can I write a test that excerises createNewHome
public void createNewHome(String address){
Address newAddress = aHome.create();
switch(state) {
case INITIAL:
//Do stuff
//Set state to INVITE
case INVITE:
//Do something else
//Set state to TERMINATE
case TERMINATE:
//Do something other
//Set state to INTIAL
break;
default:
System.out.println("Not a valid state");
}
//More code .......
}
Daniel Pitts - 14 May 2008 00:31 GMT
> Hi,
>
[quoted text clipped - 25 lines]
>
> }
Generally, you don't test state, but behavior.
you would start from a known state, simulate stimuli and then assert the
correct response to the stimuli.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Roedy Green - 14 May 2008 06:38 GMT
On Tue, 13 May 2008 11:38:06 -0700 (PDT), mike
<mikaelpetterson@hotmail.com> wrote, quoted or indirectly quoted
someone who said :
>switch(state) {
> case INITIAL:
[quoted text clipped - 11 lines]
> }
> //More code .......
see http://mindprod.com/jgloss/finitestate.html
For some ideas on how to implement state machines.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com