struts 2 action partial mocking

185 views
Skip to first unread message

Barry Mac

unread,
May 12, 2010, 8:54:06 AM5/12/10
to gmock-user
Hi all,

First time I've used Gmock and it has really helped me a lot! So much
better than using other mocking frameworks in the past. I'm using it
to test Struts action, with Struts 2.

I've come across the necessity to do some partial mocking of a method
that comes from the struts ActionSupport class which resolves messages
in message bundles. Normally at runtime the "TextProvider" is set up
which would provide the message when asked using the method
getText("message.key") but I just get null pointer exceptions.

I've tried all the following but I still get the NPE and the test
crashes out:

def controller = new CompleteRegistrationAction()
def mockLTU = mock(LocalizedTextUtil)
def mockTPS = mock(TextProviderSupport)

mock(ActionSupport).addActionError("errorString")

mock(ActionSupport).getText("registration.error.password.mismatch").returns
"errorString"
mock(controller).addActionError("errorString")
mock(controller).addActionError("errorString")
mockTPS.getText("registration.error.password.mismatch").returns
"errorString"
mockLTU.findText("registration.error.password.mismatch").returns
"errorString"


13:48:17,657 DEBUG [ActionSupport] Action context not initialized

java.lang.NullPointerException
at
com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:
362)
at
com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:
191)
at
com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:
106)
at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:
80)
at
com.web.action.registration.CompleteRegistrationAction.doExecute(CompleteRegistrationAction.java:
91)

Any ideas?

Thanks in advance.

--
You received this message because you are subscribed to the Google Groups "gmock-user" group.
To post to this group, send email to gmock...@googlegroups.com.
To unsubscribe from this group, send email to gmock-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gmock-user?hl=en.

Johnny Jian

unread,
May 13, 2010, 11:18:39 PM5/13/10
to gmock...@googlegroups.com
Partial mocking and static mocking only for the code written in Groovy, but Struts 2 itself is written in Java (LocalizedTextUtil and TextProviderSupport is part of Struts 2).

Johnny
Reply all
Reply to author
Forward
0 new messages