title: How to test if @Valid annotation is working?
body: <p>I have the following unit test:</p>
  
  <pre><code>@RunWith(SpringJUnit4ClassRunner.class)
  @SpringApplicationConfiguration(classes = {EqualblogApplication.class})
  @WebAppConfiguration
  @TestPropertySource("classpath:application-test.properties")
  public class PostServiceTest {
    // ...
  
    @Test(expected = ConstraintViolationException.class)
    public void testInvalidTitle() {
         postService.save(new Post());  // no title
    }
  }
  </code></pre>
  
  <p>The code for <code>save</code> in <code>PostService</code> is:</p>
  
  <pre><code>public Post save(@Valid Post post) {
      return postRepository.save(post);
  }
  </code></pre>
  
  <p>The <code>Post</code> class is marked with <code>@NotNull</code> in most fields.</p>
  
  <p>The problem is: <strong>no validation exception is thrown</strong>.</p>
  
  <p>However, this happens only in testing. <strong>Using the application normally runs the validation and throws the exception.</strong></p>
  
  <p>Note: I would like to do it automatically (on save) and not by manually validating and then saving (since it's more realistic).</p>