Spring Boot 1.4 - how to test a controller with the validation
<p>Spring Boot 1.4 has a number of fine features including @DataJpaTest annotation that automatically wakes up the classpath embedded database for the test purposes. As far I know, it won't work in conjuction with TestRestTemplate in bounds of the same class.</p>

<p>The following test won't work:</p>

<pre><code>@RunWith(SpringRunner.class)
@SpringBootTest
@DataJpaTest
public class PersonControllerTest {

    private Logger log = Logger.getLogger(getClass());

    private Category category;

    @Autowired
    private TestRestTemplate restTemplate;

    @Autowired
    private TestEntityManager entityManager;

    @Before
    public void init() {

        log.info("Initializing...");

        category = entityManager.persist(new Category("Staff"));
    }

    @Test
    public void personAddTest() throws Exception {

        log.info("PersonAdd test starting...");

        PersonRequest request = new PersonRequest("Jimmy");

        ResponseEntity&lt;String&gt; response = restTemplate.postForEntity("/Person/Add", request, String.class);
        assertEquals(HttpStatus.OK, response.getStatusCode());

        log.info("PersonAdd test passed");
    }
</code></pre>

<p>During startup of the test an exception will be thrown:</p>

<pre><code>Unsatisfied dependency expressed through field 'restTemplate': 
No qualifying bean of type [org.springframework.boot.test.web.client.TestRestTemplate]
</code></pre>

<p>Then guessing to switch to the recommended mock based slice approach but it won't work there because the controller looks like this:</p>

<pre><code>@RequestMapping(value="/Person/Add", method=RequestMethod.POST)
public ResponseEntity personAdd(@Valid @RequestBody PersonRequest personRequest, 
                                Errors errors) 

     personValidator.validate(personRequest, errors):

     if (errors.hasErrors())
         return new ResponseEntity(HttpStatus.BAD_REQUEST);

     personService.add(personRequest);

     return new ResponseEntity(HttpStatus.OK);
}
</code></pre>

<p>... it's easy to mock the <code>personService</code> as the documentation suggests but how to be with the <code>errors</code> object which is not mockable in this case? As far I know, there's no ways to mock it since it isn't class field or a returned value of a method.</p>

<p>So, I'm unable to test the code above using neither slice approach nor integration one since <code>@DataJpaTest</code> should not be used with a controller.</p>

<p>Is there a way to test the controller with such architecture using Spring Boot 1.4 testing features?</p>