title: Spring-boot testing a rest controller with pageable
body: <p>I'm trying to test the following controller:  </p>
  
  <pre><code>@GetMapping("movies")
  public Page&lt;Title&gt; getAllMovies(@PageableDefault(value=2) Pageable pageable){        
      return this.titleService.getTitleByType("Movie", pageable);
  }
  </code></pre>
  
  <p>and here's the test class:  </p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @WebMvcTest(TitleController.class)
  @EnableSpringDataWebSupport
  public class TitleControllerTest {
  
      @Autowired
      private MockMvc mockMvc;
  
      @MockBean
      private TitleService titleService;
  
      // Test controller method - getAllMovies
      @Test
      public void getAllMovies() throws Exception {
          Title title = new Title();
          title.setId((short)1);
          title.setName("The Godfather");
          title.setType("Movie");    
  
          List&lt;Title&gt; titles = new ArrayList&lt;&gt;();
          titles.add(title);
          Page&lt;Title&gt; page = new PageImpl&lt;&gt;(titles);
  
          given(this.titleService.getTitleByType("Movie", PageRequest.of(0,2))).willReturn(page);
          mockMvc.perform(MockMvcRequestBuilders.get("/movies"))
                  .andExpect(status().isOk());
      }
  }  
  </code></pre>
  
  <p>When i run the test it fails and gives me the following message:  </p>
  
  <pre><code>java.lang.AssertionError: Status 
  Expected :200
  Actual   :500
  </code></pre>
  
  <p>When i test the url <code>http://localhost:8080/movies</code> it works properly.</p>