2013/8/29 Mohit Gupta <motgu...@gmail.com>: > I am facing one issue while writing the junit of my struts 2 action > class.My action class has following code > snippet > > getText("customerLabel") > > While execution of junit i get below error though works fine thru > application(i think > Struts controller loads it while normal web flow which does not happen > during junit) > > java.lang.NullPointerException > at > com.opensymphony.xwork2.util.LocalizedTextUtil.findText(LocalizedTextUtil.java:361) > at > com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:208) > at > com.opensymphony.xwork2.TextProviderSupport.getText(TextProviderSupport.java:123) > at com.opensymphony.xwork2.ActionSupport.getText(ActionSupport.java:103) > > I could get it working with a workaround by below code sniipet in my test > class and asiign it to my my action annotated with annotation TestedObject > > > > action = new Myction() > { > @Override > public String getText(String textName) > { > return "mockedLabel"; > } > }; > > But i am looking for clean solution?
Mocking as your solution is perfectly fine. If you want you can do it like that in setUp: ValueStack valueStack = container.getInstance(ValueStackFactory.class).createValueStack() ActionContext.setContext(new ActionContext()) ActionContext.getContext().setValueStack(valueStack) but it doesn't look more readable ;-) Regards -- Ćukasz + 48 606 323 122 http://www.lenart.org.pl/ --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org