title: How to Mock a ResponseEntity<?> method
body: <p>I am implementing unit tests in Spring Boot but I can't get them to work.</p>
  
  <p>Here is my method n the RoulletController class.</p>
  
  <pre><code>@PutMapping("/open_roulette/")
      public ResponseEntity&lt;?&gt; enableRoluette(@RequestParam("id") Long id) {
          return rouletteService.enableRouletteById(id);
      }
  </code></pre>
  
  <p>Here is my method on the RouletteService class.</p>
  
  <pre><code>@Override
      public ResponseEntity&lt;?&gt; enableRouletteById(Long roulette_id) {
          Optional&lt;Roulette&gt; roulette = rouletteRepository.findById(roulette_id);
          HashMap&lt;String, Object&gt; response = new HashMap&lt;String, Object&gt;();
          if (roulette.isPresent()) {
              Roulette request = roulette.get();
              {
                  if (!request.isRouletteStatus())
                      request.setBets(null);
              }
              request.setRouletteStatus(true);
              rouletteRepository.save(request);
              response.put("message", "La ruleta ha sido activada con éxito");
              response.put("roulette", request);
  
              return new ResponseEntity&lt;Map&lt;String, Object&gt;&gt;(response, HttpStatus.CREATED);
          } else {
              response.put("message", "La apuesta no es correcta");
              response.put("error", HttpStatus.BAD_REQUEST);
  
              return new ResponseEntity&lt;Map&lt;String, Object&gt;&gt;(response, HttpStatus.BAD_REQUEST);
          }
      }
  </code></pre>
  
  <p>And here is my test method RoulletControllerTest class, i'm trying to do soemthing like this but i got "The method thenReturn is not applicable for the arguments, etc. </p>
  
  <pre><code>@Test
      public void testEnableRoluette() {
  
          HashMap&lt;String, Object&gt; response = new HashMap&lt;String, Object&gt;();
  
          ResponseEntity&lt;?&gt; responseEntity = new ResponseEntity&lt;Map&lt;String, Object&gt;&gt;(response, HttpStatus.CREATED);
  
          Mockito.when(rouletteService.enableRouletteById(14L)).thenReturn(responseEntity);
          assertEquals(rouletteController.enableRoluette(14L), responseEntity);
      }
  </code></pre>
  
  <p>Thank you.</p>