title: Test Spring boot rest api but output not excepted
body: <p>i just learn about spring mock test and run a simple rest api app with spring mocktest in maven test and eclipse IDE, but my output is 400 but my api run ok in PostMan and reactjs, i use security too but i dont think i should it here</p>
  <p>here is my api controller</p>
  <p><strong>Trending</strong></p>
  <pre class="lang-java prettyprint-override"><code>///my DI
  @Autowired
      private BlogService blogService;
      @Autowired
      private TypeService typeService; 
  
  @GetMapping(&quot;/trending&quot;)
      @JsonView(BlogView.List.class)
      public ResponseEntity&lt;?&gt; blogTrending(@RequestParam int start, @RequestParam int size,
                                            @RequestParam String sort) {
          Page&lt;Blog&gt; blogs = blogService.findAll(sort, size, start, &quot;statView&quot;);
          return ResponseEntity.ok(pageToJson(blogs));
     }
  
  
   private Map&lt;String, Object&gt; pageToJson(Page&lt;Blog&gt; blogs) {
          List&lt;BlogDTO&gt; listBlog = ObjectMapperUtils.mapAll(blogs.getContent(), BlogDTO.class);
          return new HashMap&lt;String, Object&gt;() {/**
               * 
               */
              private static final long serialVersionUID = 1L;
  
          {
              put(&quot;blogs&quot;, listBlog);
              put(&quot;size&quot;, blogs.getTotalPages());
              put(&quot;page&quot;, blogs.getNumber());
          }};
      }
  </code></pre>
  <p>here is my test class</p>
  <pre class="lang-java prettyprint-override"><code>@WebMvcTest(BlogController.class)
  public class BlogControllerTesting {
  
      @MockBean
      private BlogService blogService;
  
      @MockBean
      private TypeService typeService;
  
      @MockBean
      private AccountService accountService;
  
      @MockBean
      private JwtUtils jwtUtils;
  
      @MockBean
      private JwtEntryPoint entryPoint;
  
      @Autowired
      private MockMvc mockMvc;
  
      @Test
      public void shouldReturnDefaultMessage() throws Exception {
          this.mockMvc.perform(get(&quot;/api/blog/trending?start=0&amp;size=5&amp;sort=ASC&quot;)).andDo(print())
                  .andExpect(status().isOk());
      }
  }
  </code></pre>
  <p>my output when i running test</p>
  <pre><code>MockHttpServletRequest:
        HTTP Method = GET
        Request URI = /api/blog/trending
         Parameters = {start=[0], size=[5], sort=[ASC]}
            Headers = []
               Body = null
      Session Attrs = {}
  
  Handler:
               Type = com.springboot.app.controller.BlogController
             Method = com.springboot.app.controller.BlogController#blogTrending(int, int, String)
  
  Async:
      Async started = false
       Async result = null
  
  Resolved Exception:
               Type = java.lang.NullPointerException
  
  ModelAndView:
          View name = null
               View = null
              Model = null
  
  FlashMap:
         Attributes = null
  
  MockHttpServletResponse:
             Status = 400
      Error message = null
            Headers = [Vary:&quot;Origin&quot;, &quot;Access-Control-Request-Method&quot;, &quot;Access-Control-Request-Headers&quot;, X-Content-Type-Options:&quot;nosniff&quot;, X-XSS-Protection:&quot;1; mode=block&quot;, Cache-Control:&quot;no-cache, no-store, max-age=0, must-revalidate&quot;, Pragma:&quot;no-cache&quot;, Expires:&quot;0&quot;, X-Frame-Options:&quot;DENY&quot;]
       Content type = null
               Body = 
      Forwarded URL = null
     Redirected URL = null
            Cookies = []
  
  MockHttpServletRequest:
        HTTP Method = GET
        Request URI = /api/blog/trending
         Parameters = {start=[0], size=[5], sort=[ASC]}
            Headers = []
               Body = null
      Session Attrs = {}
  
  Handler:
               Type = com.springboot.app.controller.BlogController
             Method = com.springboot.app.controller.BlogController#blogTrending(int, int, String)
  
  Async:
      Async started = false
       Async result = null
  
  Resolved Exception:
               Type = java.lang.NullPointerException
  
  ModelAndView:
          View name = null
               View = null
              Model = null
  
  FlashMap:
         Attributes = null
  
  MockHttpServletResponse:
             Status = 400
      Error message = null
            Headers = [Vary:&quot;Origin&quot;, &quot;Access-Control-Request-Method&quot;, &quot;Access-Control-Request-Headers&quot;, X-Content-Type-Options:&quot;nosniff&quot;, X-XSS-Protection:&quot;1; mode=block&quot;, Cache-Control:&quot;no-cache, no-store, max-age=0, must-revalidate&quot;, Pragma:&quot;no-cache&quot;, Expires:&quot;0&quot;, X-Frame-Options:&quot;DENY&quot;]
       Content type = null
               Body = 
      Forwarded URL = null
     Redirected URL = null
            Cookies = []
  </code></pre>
  <p>another information</p>
  <p><a href="https://i.stack.imgur.com/39WlM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/39WlM.png" alt="enter image description here" /></a></p>