title: Mockito unit testing RestTemplate
body: <p>I am using RestTemplate <code>postForEntity</code> method to post body to an endpoint. I need help with writing test case for my code using Mockito. The return type is void but it can be changed to <code>Types</code> or <code>code</code> if needed to test. I have referred many other documentation but they are very general, I tried using them but most did not work for me as the <code>request</code> and return type are different. . Any suggestions are appreciated. Thank you </p>
  
  <p>Here is my Java class</p>
  
  <pre><code>    public void postJson(Set&lt;Type&gt; Types){
          try {
              String oneString = String.join(",", Types);
             Map&lt;String, String&gt; requestBody = new HashMap&lt;&gt;();
              requestBody.put("type", oneString);
              JSONObject jsonObject = new JSONObject(requestBody);
              HttpEntity&lt;String&gt; request = new HttpEntity&lt;String&gt;(jsonObject.toString(), null);
  ResponseEntity result = restTemplate.exchange(url, HttpMethod.POST,
                      new HttpEntity&lt;&gt;(request, getHttpHeaders()), String.class);
  
          } 
      }
  } 
  </code></pre>