title: MockMvc test POST request
body: <p>I have the following post route in my REST controller:</p>
  
  <pre class="lang-java prettyprint-override"><code>     @RequestMapping(value = "", method = RequestMethod.POST, produces = 
      "application/json")
      public ResponseEntity saveMovie(@RequestBody Movie movie){
          movieService.saveMovie(movie);
          return new ResponseEntity&lt;Movie&gt;(movie, HttpStatus.OK);
      }
  </code></pre>
  
  <p>The route uses a service to add the movie passed in request body in data store.
  The signature of the service method is this:</p>
  
  <pre class="lang-java prettyprint-override"><code>    Movie saveMovie(Movie movie);
  </code></pre>
  
  <p>I have written the following test and a helper method for it:</p>
  
  <pre class="lang-java prettyprint-override"><code>      @Test
        public void saveMovie() throws Exception {
          Movie movie1 = new Movie();
          movie1.setImdbID("imdb1");
          movie1.setTitle("Meter");
          movie1.setYear("2015");
          movie1.setPoster("meter.jpg");
  
          when(movieService.saveMovie(movie1)).thenReturn(movie1);
          mockMvc.perform(post("/v1/api/movie")
                  .contentType(MediaType.APPLICATION_JSON_UTF8)
                  .content(asJsonString(movie1))
                  .accept(MediaType.APPLICATION_JSON))
                  .andExpect(status().isOk())                   
                  .andExpect(content().contentType
                       (MediaType.APPLICATION_JSON_UTF8_VALUE));
                   verify(movieService, times(1)).saveMovie(movie1);
                   verifyNoMoreInteractions(movieService);
      }
  
  
  
      public static String asJsonString(final Object obj) {
          try {
              final ObjectMapper mapper = new ObjectMapper();
              final String jsonContent = mapper.writeValueAsString(obj);
              System.out.println(jsonContent);
              return jsonContent;
          } catch (Exception e) {
              throw new RuntimeException(e);
          }
      }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>    Argument(s) are different! Wanted:
       com.stackroute.ng2boot.service.MovieService#0 bean.saveMovie(
         com.stackroute.ng2boot.domain.Movie@ae372b9
       );
       -&gt; at 
  
       com.stackroute.ng2boot.controllers.MovieRestControllerTest.
       saveMovie(MovieRestControllerTest.java:129)
       Actual invocation has different arguments:
      com.stackroute.ng2boot.service.MovieService#0 bean.saveMovie(
      com.stackroute.ng2boot.domain.Movie@2098d37d
      );
      -&gt; at     
      com.stackroute.ng2boot.controllers.MovieRestController.
      saveMovie(MovieRestController.java:60)
  </code></pre>
  
  <p>Except save and update, where I need to pass a Movie JSON as request body, the other routs are passing tests. Please share your valuable inputs.</p>
  
  <p>Thanks in advance.</p>