Expert Spring MVC and Web Flow

(Dana P.) #1

Listing 6-28.TwoDatesCommand Class


public class TwoDatesCommand {


private Date firstDate;
private Date secondDate;

public Date getFirstDate() {
return firstDate;
}
public void setFirstDate(Date firstDate) {
this.firstDate = firstDate;
}
public Date getSecondDate() {
return secondDate;
}
public void setSecondDate(Date secondDate) {
this.secondDate = secondDate;
}
}


Listing 6-29 simply shows the XHTML form for both dates.

Listing 6-29.TwoDates HTML Form




First Date: (YYYY-MM-DD)



Second Date: (DD-MM-YYYY)




Listing 6-30.TwoDatesCommand Unit Test


protected void setUp() throws Exception {
bean = new TwoDatesCommand();
request = new MockHttpServletRequest();
binder = new ServletRequestDataBinder(bean, "bean");
}


public void testBind() throws Exception {
SimpleDateFormat firstDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date firstExpected = firstDateFormat.parse("2001-01-01");


SimpleDateFormat secondDateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date secondExpected = secondDateFormat.parse("01-01-2001");

CHAPTER 6 ■THE CONTROLLER MENAGERIE 141
Free download pdf