As simples as it may seem. Assuming you're creating an instance on your setUp
method, and just to make things funnier, using a facade mock which is
expected to be action constructor parameter, it would look like this:

...
Mockery mockContext = new Mockery();
SomeFacade someFacadeMock;
MyAction myAction;

@Before
public void setUp() throws Exception {
    someFacadeMock = mockContext.mock(SomeFacade.class);
    myAction = new MyAction(someFacadeMock) {
        @Override
        public String getText(String textName) {
            return "dummy";
        }
    }
}
...

This way you can assume any calls to ActionSupport#getText(String) will
return dummy. You can even make some assertions on that (assuming you are
using it to set an action error), like:

...
assertTrue(myAction.getActionErrors.contains("dummy"));
...

By now you might have figured that, but worth the time to expose a possible
and simple solution.

Cya,


Adam Hardy (debian) wrote:
> 
> I am unit testing my MVC layer and looking for the best way to override
> ActionSupport.getText() cleanly and efficiently for testing purposes (from
> a developer time point of view).
> 
> Rather than reinventing the wheel, is there anything out there now that
> people are willing to share? (Did I miss it somewhere?)
> 
> Fortunately I already have my own Action subclass which inherits
> ActionSupport, so it shouldn't be too difficult to implement, but it would
> be nice to be able to sort out it quickly (in the background I hear the
> unmistakeable splat of another unforeseen coding session hitting the
> project time line...)
> 
> For anyone reading this msg in the archives, when I've got something
> (self-created or other) I'll see if I can put it up on the web somewhere -
> in the wiki or even in a msg here.
> 
> Regards
> Adam
> 

-- 
View this message in context: 
http://www.nabble.com/any-struts-2-unit-testers-out-there--tp13437046p24006147.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org

Reply via email to