String id = new NonFacesRequest("/numberGuess.jsp")
{
@Override
protected void renderResponse() throws Exception {
Game game = (Game) getInstance(Game.class);
Guess guess = (Guess) getInstance(Guess.class);
assert game.getBiggest()==100;
assert game.getSmallest()==1;
assert guess.getValue()==null;
assert game.getGuessCount()==0;
assert Manager.instance().isLongRunningConversation();
}
}.run();
for (int i=1; i<=9; i++)
{
final int count = i;
new FacesRequest("/numberGuess.jsp", id)
{
@Override
protected void applyRequestValues() throws Exception {
Guess guess = (Guess) getInstance(Guess.class);
guessedValue = getRandomNumber() > 50 ? 25+count : 75-count;
guess.setValue(guessedValue);
}
@Override
protected void invokeApplication() throws Exception {
setOutcome("guess");
//ng.guess();
//assert Pageflow.instance().getProcessInstance().getRootToken()
// .getNode().getName().equals("displayGuess");
}
@Override
protected void afterRequest()
{
assert !isRenderResponseBegun();
assert getViewId().equals("/numberGuess.jsp");
}
}.run();
new NonFacesRequest("/numberGuess.jsp", id)
{
@Override
protected void renderResponse() throws Exception {
Game game = (Game) getInstance(Game.class);
Guess guess = (Guess) getInstance(Guess.class);
assert ( guessedValue > getRandomNumber() && game.getBiggest()==guessedValue-1 )
|| ( guessedValue < getRandomNumber() && game.getSmallest()==guessedValue+1 );
assert guess.getValue().equals(guessedValue);
assert game.getGuessCount()==count;
assert Manager.instance().isLongRunningConversation();
assert Pageflow.instance().getProcessInstance().getRootToken()
.getNode().getName().equals("displayGuess");
}
}.run();
}
new FacesRequest("/numberGuess.jsp", id)
{
@Override
protected void applyRequestValues() throws Exception {
Guess guess = (Guess) getInstance(Guess.class);
guessedValue = getRandomNumber() > 50 ? 49 : 51;
guess.setValue(guessedValue);
}
@Override
protected void invokeApplication() throws Exception {
setOutcome("guess");
//ng.guess();
assert Pageflow.instance().getProcessInstance().getRootToken()
.getNode().getName().equals("displayGuess");
}
@Override
protected void afterRequest()
{
assert !isRenderResponseBegun();
assert getViewId().equals("/lose.jsp");
}
}.run();
new NonFacesRequest("/lose.jsp", id)
{
@Override
protected void renderResponse() throws Exception {
Guess guess = (Guess) getInstance(Guess.class);
Game game = (Game) getInstance(Game.class);
assert ( guessedValue > getRandomNumber() && game.getBiggest()==guessedValue-1 )
|| ( guessedValue < getRandomNumber() && game.getSmallest()==guessedValue+1 );
assert guess.getValue().equals(guessedValue);
assert game.getGuessCount()==10;
assert !Manager.instance().isLongRunningConversation();
assert Pageflow.instance().getProcessInstance().getRootToken()
.getNode().getName().equals("lose");
}