title: Spring MockMVC how to mock @RequestParam Date type
body: <p>I have a code to test as follows:</p>
  
  <pre><code>@RequestMapping(value = "/prepareLic", method = {RequestMethod.GET})
      public @ResponseBody
      String prepareLice(HttpServletRequest request, @RequestParam String test1, @RequestParam String test2, @RequestParam String test3, @RequestParam String test4, @RequestParam Date liPrintDate, @RequestParam String test5, @RequestParam String test6, @RequestParam String test7) throws NSException, SQLException, ParseException {
        ...
          return new Gson().toJson(jsonResponse);
      }
  </code></pre>
  
  <p>Unit test define below:</p>
  
  <pre><code>   mockMvc.perform(get("/prepareLic").param("test1", "12").param("test2" ,"cpomName").param("test3", "123").param("test4", "signeeName").
              param("liPrintDate", "22/09/2015").param("test5", "12").param("test6", "O2").param("test7", "12")).andDo(print())
              .andExpect(status().isOk()
              );
  </code></pre>
  
  <p>When I execute the above unit test the following error is displayed:</p>
  
  <pre><code>      Running com.ApControllerTest
  log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
  log4j:WARN Please initialize the log4j system properly.
  
  MockHttpServletRequest:
           HTTP Method = GET
           Request URI = /prepareLice
            Parameters = {test1=[test1], test2=[test2], test3=[test3], test4=[test4], liPrintDate =[22/09/2015], test6=[test6], test7=[test7], test8=[test8]}
               Headers = {}
  
               Handler:
                  Type =com.ApController
                Method = public java.lang.Stringcom.ApController.prepareLice(javax.servlet.http.HttpServletRequest,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.util.Date,java.lang.String,java.lang.String,java.lang.String) throws com.dummy.util.NSException,java.sql.SQLException,java.text.ParseException
  
    Resolved Exception:
                  Type = org.springframework.beans.TypeMismatchException
  
          ModelAndView:
             View name = null
                  View = null
                 Model = null
  
              FlashMap:
  
  MockHttpServletResponse:
                Status = 400
         Error message = null
               Headers = {}
          Content type = null
                  Body = 
         Forwarded URL = null
        Redirected URL = null
               Cookies = []
  Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 6.056 sec &lt;&lt;&lt; FAILURE! - in com.ApControllerTest
  prepareLiceTest(com.ApControllerTest)  Time elapsed: 2.406 sec  &lt;&lt;&lt; FAILURE!
  java.lang.AssertionError: Status expected:&lt;200&gt; but was:&lt;400&gt;
      at com.ApControllerTest.prepareLiceTest(ApControllerTest.java:1606)
  
  
  Results :
  
  Failed tests: 
    ApControllerTest.prepareLiceTest:1606 Status expected:&lt;200&gt; but was:&lt;400&gt;
  
  Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
  
  ------------------------------------------------------------------------
  BUILD FAILURE
  ------------------------------------------------------------------------
  </code></pre>
  
  <p>The exception is triggered because liPrintDate is a date object but in the above test it is defined as a String.</p>
  
  <p>Please find import below:</p>
  
  <pre><code>import com.google.gson.Gson;
  import com.google.gson.GsonBuilder;
  import com.google.gson.JsonArray;
  import com.google.gson.JsonElement;
  import com.google.gson.JsonParser;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.math.BigDecimal;
  import java.security.Principal;
  import java.sql.SQLException;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Date;
  import java.util.Enumeration;
  import java.util.GregorianCalendar;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.List;
  import java.util.Locale;
  import java.util.Map;
  import java.util.Properties;
  import java.util.Set;
  import java.util.Vector;
  import java.util.logging.Level;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import net.sf.jasperreports.engine.JRDataSource;
  import net.sf.jasperreports.engine.JRException;
  import net.sf.jasperreports.engine.JasperCompileManager;
  import net.sf.jasperreports.engine.JasperReport;
  import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
  import net.sf.jasperreports.engine.design.JasperDesign;
  import net.sf.jasperreports.engine.xml.JRXmlLoader;
  import org.apache.commons.collections.FactoryUtils;
  import org.apache.commons.collections.list.LazyList;
  import org.apache.commons.lang.StringUtils;
  import org.apache.log4j.Logger;
  import org.apache.poi.util.IOUtils;
  import org.owasp.esapi.ESAPI;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.propertyeditors.CustomDateEditor;
  import org.springframework.beans.support.PagedListHolder;
  import org.springframework.context.MessageSource;
  import org.springframework.format.annotation.DateTimeFormat;
  import org.springframework.security.core.context.SecurityContextHolder;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.validation.BindingResult;
  import org.springframework.validation.ObjectError;
  import org.springframework.web.bind.WebDataBinder;
  import org.springframework.web.bind.annotation.InitBinder;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.ResponseBody;
  import org.springframework.web.context.request.RequestContextHolder;
  import org.springframework.web.servlet.ModelAndView;
  import org.springframework.web.servlet.mvc.support.RedirectAttributes;
  </code></pre>
  
  <p>How can I define <strong>liPrintDate</strong> as Date in the above unit test since .param takes only String ?</p>
  
  <p>Thanks in advance for any advice.</p>