{
initFlags();
final Response originalResponse = newResponse();
final IRequestCycle requestCycle = newRequestCycle(originalResponse);
final RequestHandlerStack stack = newStack(requestCycle);
final IRequestHandler handler4 = new IRequestHandler()
{
public void respond(IRequestCycle requestCycle)
{
testFlag4 = false;
assertEquals(requestCycle.getResponse(), originalResponse);
requestCycle.setResponse(newResponse());
}
public void detach(IRequestCycle requestCycle)
{
detachedFlag4 = true;
}
};
final IRequestHandler handler3 = new IRequestHandler()
{
public void respond(IRequestCycle requestCycle)
{
testFlag3 = false;
requestCycle.setResponse(newResponse());
stack.replaceAll(handler4);
// code must not be reached
testFlag3 = true;
}
public void detach(IRequestCycle requestCycle)
{
detachedFlag3 = true;
}
};
final IRequestHandler handler2 = new IRequestHandler()
{
public void respond(IRequestCycle requestCycle)
{
testFlag2 = false;
requestCycle.setResponse(newResponse());
stack.execute(handler3);
// code must not be reached
testFlag2 = true;
}
public void detach(IRequestCycle requestCycle)
{
detachedFlag2 = true;
}
};
IRequestHandler handler1 = new IRequestHandler()
{
public void respond(IRequestCycle requestCycle)
{
testFlag1 = false;
requestCycle.setResponse(newResponse());
stack.execute(handler2);
// code must not be reached
testFlag1 = true;
}
public void detach(IRequestCycle requestCycle)
{
detachedFlag1 = true;
}
};
stack.execute(handler1);
assertEquals(requestCycle.getResponse(), originalResponse);
stack.detach();
assertFalse(testFlag1);
assertFalse(testFlag2);
assertFalse(testFlag3);
assertFalse(testFlag4);