Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Working with Session in Mock Objects

 
Chad Cook
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, I'm beating myself senseless trying to get my JUnit fired off that's using MockObjects, but after I set attributes in my session I can't retrieve them, I keeep getting an error saying that it can't find my FPASession (the object that I want to retrieve from the session).

So here's the code that I'm using (the line that fails is in bold):

MockHttpServletRequest mockRequest = new MockHttpServletRequest();

FPASession fpaSession = new FPASession();

MockHttpSession mockSession = new MockHttpSession();

mockSession.setAttribute(FPAUIConstants.FPA_SESSION, fpaSession);

FPASession testFPASession = (FPASession) mockSession.getAttribute(FPAUIConstants.FPA_SESSION);

mockRequest.setSession(mockSession);

Any ideas why I can't retrieve the FPASession object after I set it in the Mock Object session?
[ December 02, 2004: Message edited by: Chad Cook ]
 
Chad Cook
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind folks, I found the answer.

It turns out that you have to call setupGetAttribute() to set the attribute, rather than setAttribute().

All is working well now.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic