Unit Testing Action Classes in Seam

Posted on Friday, February 26, 2010


As we had already seen in the Recommended Seam Architecture, the UI event handling is done with the help of Action classes. These are Seam Action classes and their main purpose is UI event handling and handling the presentation logic. Testing action classes in Seam is not very different from the way we test the Service layer.

Here the idea is to again use Mockito and SeamTest. We would be mocking all interactions that the Action class would be making with any other component.

The idea for testing the Action classes would be to see that the presentation logic and the UI event handling logic is correct. Refer to the following code segment.

public class SearchActionTest extends SeamTest {

 private SearchAction searchAction;

 private Log log;

 private CompanyService companyService;

 private CompanySearchCriteria searchCriteria;

 public void setUp() {
 searchAction = new SearchAction();
 searchCriteria = new CompanySearchCriteria();

 setField(searchAction, "companyService", companyService);
 setField(searchAction, "log", log);
 setField(searchAction, "companySearchCriteria", searchCriteria);

 public void shouldSearchCompany() {
 List<Company> companies = new ArrayList<Company>();
 Company company = new Company("00-884-2922", "GOOGLE INC.", "?", new Location("2001 6TH AVE", "SEATTLE", "98121-2855", "WA", "US",



 verify(companyService, times(1)).findCompanies(searchCriteria);

 Company searchedCompany = companyService.findCompanies(searchCriteria).iterator().next();

 Assert.assertEquals(company.getName(), searchedCompany.getName());

Posted in: Java