I'm testing out my project I found that I getting an exception on the
following code that I think perfectly fine. The implementation of
MockHttpSession only allows you to access an attribute once in the
session. If you have the following code, an exception will thrown.
if (_session.getAttribute("myAttribute") != null) {
myAttribute = (String) _session.getAttribute("myAttribute");
} else {
throw new missingImportantDataExecption();
}
In my test, I have
setupGetAttribute(myAttribute, "really important info");
The problem just by reading the _session.getAttribute("myAttribute") in
the test condition will eliminate the value and cause an exception at
myAttribute = (String) _ session.getAttribute("myAttribute");
I expect that what your intention is that I should have
setupGetAttribute(myAttribute, "really important info");
setupGetAttribute(myAttribute, "really important info");
to show that I plan to access the attribute twice. I doubt that many
users will anticipate this. It is just not how Servlet API works, so I
think most developer will be surprised by this..
I look forward to your comments.
Regards,
Jeff Duska
|