title: Testing Bad Request while posting an incomplete entity with Spring Boot
body: <p>I'm trying to test the creation of an entity with incomplete data as follows:</p>
  
  <pre><code>@Test
  public void postVisitor_withIncompleteData_shouldFailWithBadRequest() throws Exception {
      Visitor emptyVisitor = new Visitor();
  
      mockMvc.perform(post("/visits")
              .contentType(APPLICATION_JSON)
              .content(objectMapper.writeValueAsString(visitor))
              ).andExpect(status().isBadRequest());
  }
  </code></pre>
  
  <p>But my test fails with this error:</p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.validation.ConstraintViolationException: Validation failed for classes [com.reweb.Visitor] during persist time for groups [javax.validation.groups.Default, ]
  List of constraint violations:[
      ConstraintViolationImpl{interpolatedMessage='cannot be empty', propertyPath=email, rootBeanClass=class com.reweb.Visitor, messageTemplate='{javax.validation.constraints.NotEmpty.message}'}
  ]
  </code></pre>
  
  <p>How can I test this is a bad request?</p>
  
  <p>Adding <code>@Test(expected = ConstraintViolationException.class)</code> wouldn't work either.</p>