title: Mocking RestTemplate.exchange() gives URI is not absolute exception
body: <p>I am trying to mock this service that calls an API using rest template and returns a List. </p>
  
  <p>I am unable to mock the <code>restTemplate.exchange()</code> method. It's giving me a "java.lang.IllegalArgumentException: URI is not absolute" exception. </p>
  
  <p><strong>edit- My stupid self forgot to put http:// before the base url in the test case and that is why I was getting that. Thanks for helping and apologies for wasting your time.</strong> </p>
  
  <p>Method to be tested </p>
  
  <pre><code>@Value("${base-url}")
  private String baseUrl;
  
  @Override
  public List&lt;Currency&gt; getCurrencyList() {
      RestTemplate restTemplate = new RestTemplate();
      String url = baseUrl + "/currency";
      ResponseEntity&lt;List&lt;Currency&gt;&gt; result;
      HttpHeaders headers = new HttpHeaders();
      headers.setContentType(MediaType.APPLICATION_JSON);
      HttpEntity&lt;String&gt; dataHttpEntity = new HttpEntity&lt;&gt;(headers);
      log.info(url);
      result = restTemplate.exchange(url, HttpMethod.GET,dataHttpEntity, new ParameterizedTypeReference&lt;List&lt;Currency&gt;&gt;() {
      });
      return result.getBody();
  }
  </code></pre>
  
  <p>The Testing code</p>
  
  <pre><code>@Test
  public void getCurrencyListTest() {
     ResponseEntity&lt;List&lt;Currency&gt;&gt; result = ResponseEntity.ok(currencyList);
  
      when(restTemplate.exchange( ArgumentMatchers.anyString(),
              ArgumentMatchers.any(HttpMethod.class),
              ArgumentMatchers.any(),
              ArgumentMatchers.&lt;Class&lt;List&lt;Currency&gt;&gt;&gt;any())).thenReturn(result);
       assertEquals(currencyList,service.getCurrencyList());
  }
  </code></pre>
  
  <p>Exception </p>
  
  <pre><code>java.lang.IllegalArgumentException: URI is not absolute
  
  at java.net.URI.toURL(URI.java:1088)
  at org.springframework.http.client.SimpleClientHttpRequestFactory.createRequest(SimpleClientHttpRequestFactory.java:145)
  at org.springframework.http.client.support.HttpAccessor.createRequest(HttpAccessor.java:87)
  at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:721)
  at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:682)
  at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:627)
  at com.fpts.seller.service.external.impl.DocumentServiceImpl.getCurrencyList(DocumentServiceImpl.java:34)
  at com.fpts.seller.service.external.DocumentServiceImplTest.getCurrencyListTest(DocumentServiceImplTest.java:105)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:78)
  at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:84)
  at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
  at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:161)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
  at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
  at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
  at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
  </code></pre>