title: TestRestTemplate doesn't detect the resouce which has been mocked in a SpringBootTest
body: <pre><code>@RunWith(SpringJUnitRunner.class)    
  @SpringBootTest(classes = Application.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOMPORT)   
  class ResourceTest {
      @Autowired
      private TestRestTemplate testRestTemplate;
  
      @MockBean
      private AuthService authService; //This is used in the method being hit by the testRestTemplate.
  
      @Before
      public void setUp() extends Exception {
          given(this.authService.auth(user)).willReturn(user); //given mock object some behaviour
          //Some Code
          MockitoAnnotations.initMocks(this);
      }
  
      @Test
      public void testAuthValidParameters() throws Exception {
          //Assume Every Parameter is appropriate
          HttpEntity&lt;String&gt; request = new HttpEntity&lt;&gt;(postBody,headers);
          //The Exception occurs here
          ResponseEntity&lt;String&gt; responseEntity = this.testRestTemplate.postForEntity("/path/auth/",request,String.class);
          //Some asserts and other tests
      }
  }
  </code></pre>
  
  <p>The exception is as follows</p>
  
  <pre><code>org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:53234/path/auth/"
  </code></pre>
  
  <p>The problem doesn't occur when I don't Mock and let the actual methods run or I use Mock directly (seems like Normal Mock in combination with PowerMock doesn't actually effect the method being called). They are executed and this is being integrated test which doesn't solve the problem.</p>
  
  <p>So, when I use MockBean this exception arises. What might be the root cause and how could I solve it.</p>
  
  <hr>
  
  <p>Edit 1: </p>
  
  <p>Using almost same code and changing the mock stubbing in setUp like</p>
  
  <pre><code>when(authService.authenticate(any(User.class))).thenReturn(user);
  </code></pre>
  
  <p>I get a Http Code 400. Does this mean it is hitting the server? Which might imply that it is picking up the MockBean but the parameters which haven't been changed at all are being rejected.</p>