title: Spring boot 1.4 - REST API Testing
body: <p>i wanted to write Test for my Spring mvc REST Controller. I am following official documentation from <a href="https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4" rel="nofollow noreferrer">https://spring.io/blog/2016/04/15/testing-improvements-in-spring-boot-1-4</a> and so just updated version <code>to 1.4</code> and added spring boot as doc suggests.</p>
  
  <p>I have added following dependencies :</p>
  
  <pre><code> &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
  &lt;/dependency&gt;
  
  &lt;dependency&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-tomcat&lt;/artifactId&gt;
      &lt;scope&gt;provided&lt;/scope&gt;
  &lt;/dependency&gt; 
  </code></pre>
  
  <p>and the parent</p>
  
  <pre><code> &lt;parent&gt;
      &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
      &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
      &lt;version&gt;1.4.2.RELEASE&lt;/version&gt;
    &lt;/parent&gt;
  </code></pre>
  
  <p>My LoginController API which i want to test looks like this :</p>
  
  <pre><code>@RequestMapping(value = { "/login" }, method = RequestMethod.GET)
      public @ResponseBody ResponseEntity&lt;HashMap&lt;String, Object&gt;&gt; login() {
  
  
            // some logic to get Customer
          return new ResponseEntity&lt;&gt;(customer, HttpStatus.OK);
  
      }
  </code></pre>
  
  <p>And as per documentation here is my Test :</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(LoginController.class)
  @SpringBootTest
  public class AuthorizationAndAuthenticationTest extends WebSecurityConfigurerAdapter {
  
      @Autowired
      private WebApplicationContext webApplicationContext;
      private LoginController loginController;
      @Autowired
      private TestRestTemplate restTemplate;
  
      @MockBean
      private LoggingService loggingService;
  
      @Test
      public void test() {
          given(this.loggingService.logInfoMessage("some Dummy Message", this.getClass())).
          this.restTemplate.getForObject("/login", Object.class);
      }
  }
  </code></pre>
  
  <p><strong>Problems</strong> :
  1. Since login Controller is using many Services, i wanted to Mock them using <strong>"given"</strong>  but it gives compilation problem, seems like i am missing some dependency though not sure.
  2.TestRestTemplate is deprecated and what is the alternative ? i did not find any alternative. </p>
  
  <p>This is first time i will be writing Tests using Spring framework so it is possible i am overlooking some minute details.</p>
  
  <p>Please help me with this.</p>