title: @RequestParam javax validation junit REST controller testing
body: <p>Is there a way to do spring controller unit testing for javax validations on @RequestParams.</p>
  
  <p>I have a get method in controller which validates the size of the request param with @Size.</p>
  
  <pre><code>@RequestMapping(value = "/getData", method = RequestMethod.GET)
      public ResultgetData(
  
              @Size(min=2, max=3)
               @RequestParam String number)
  </code></pre>
  
  <p>Is there a way to mock junit test the size validator? I would like to validate a error returned when the size  is &lt;2 or > 3. </p>
  
  <p>Sample test :</p>
  
  <p>@RunWith(MockitoJUnitRunner.class)
  public class MyControllerTest {</p>
  
  <pre><code>private MockMvc mockMvc;
  
  @InjectMocks
  private MyController myControllerMock;
  
  
  @Before
  public void initTest() {
      mockMvc = MockMvcBuilders.standaloneSetup(customerInsuranceControllerMock).setControllerAdvice(exceptionHandler).build();
  }
  
  @Test
  public void getEmptyData() throws Exception{
  
  
  
      mockMvc.perform(MockMvcRequestBuilders.get(
          "/getData?number={number}"
          , "")
          .andExpect(MockMvcResultMatchers.status().isBadRequest());  // This is failing. It returns a success as javax @Size is not triggered.When a empty string is passed , it should be bad request
  </code></pre>
  
  <p>}</p>
  
  <p>I tried spring runner too ,but still seems to fail.</p>
  
  <p>Thanks</p>