### Question:
PostCRUDController implements InitializingBean { @RequestMapping(value = { URL.Post.HOME, URL.Post.LIST }, method = RequestMethod.GET) public String list(Model model, Pageable pageRequest) { final PageWrapper<Post> postList = new PageWrapper<Post>(postService.getPost(pageRequest), URL.Post.LIST); if (postList.getSize() == 0) { LOG.info("No post found redirect to create"); return URL.redirect(URL.Post.CREATE); } model.addAttribute("pageRequest", pageRequest); model.addAttribute("postList", postList); return "example/post/list"; }  @InitBinder void initBinder(final WebDataBinder binder); @Override void afterPropertiesSet(); @RequestMapping(value = { URL.Post.HOME, URL.Post.LIST }, method = RequestMethod.GET) String list(Model model, Pageable pageRequest); @RequestMapping(value = URL.Post.CREATE, method = RequestMethod.GET) String create(Model model); @RequestMapping(value = URL.Post.CREATE, method = RequestMethod.POST) String insert(@ModelAttribute("post") Post post,
            BindingResult result, Model model); @RequestMapping(value = URL.Post.DELETE, method = RequestMethod.GET) String deleteConfirm(@PathVariable(URL.Post.P_POSTID) Long postId,
            Model model); @RequestMapping(value = URL.Post.DELETE, method = { RequestMethod.DELETE, RequestMethod.POST }) String delete(@PathVariable(URL.Post.P_POSTID) Long postId); @RequestMapping(value = URL.Post.SHOW, method = RequestMethod.GET) String show(@PathVariable(URL.Post.P_POSTID) Post post, Model model); @RequestMapping(value = URL.Post.EDIT, method = RequestMethod.GET) String edit(@PathVariable(URL.Post.P_POSTID) Long postId, Model model); @RequestMapping(value = URL.Post.PARTIALEDIT, method = RequestMethod.GET) String editSimpleFields(
            @PathVariable(URL.Post.P_POSTID) Long postId, Model model); @RequestMapping(value = URL.Post.EDIT, method = RequestMethod.POST) String update(@ModelAttribute("post") Post post,
            BindingResult result, Model model); @RequestMapping(value = URL.Post.PARTIALEDIT, method = RequestMethod.POST) String updatePartial(@RequestParam("id") Post post,
            HttpServletRequest request, Model model);  }### Answer:
@SuppressWarnings("boxing") @Test public void testListEmptyList() { final Pageable pageRequest = mock(Pageable.class); @SuppressWarnings("unchecked") final Page<Post> pageResult = mock(Page.class); when(postService.getPost(pageRequest)).thenReturn(pageResult); when(pageResult.getSize()).thenReturn(0); final String result = testee.list(model, pageRequest); assertThat(result).isEqualTo(URL.redirect(URL.Post.CREATE)); }
@SuppressWarnings({ "unchecked", "boxing" }) @Test public void testList() { final int nrOfEntries = 100; final Pageable pageRequest = mock(Pageable.class); final Page<Post> pageResult = mock(Page.class); when(postService.getPost(pageRequest)).thenReturn(pageResult); when(pageResult.getSize()).thenReturn(nrOfEntries); final String result = testee.list(model, pageRequest); assertThat(result).isEqualTo("example/post/list"); assertThat(model.containsAttribute("postList")).isTrue(); assertThat(model.containsAttribute("pageRequest")).isTrue(); final Map<String, Object> map = model.asMap(); assertThat(map.get("postList")).isInstanceOf(PageWrapper.class); assertThat(map.get("pageRequest")).isSameAs(pageRequest); final PageWrapper<Post> pageWrapper = (PageWrapper<Post>) map.get("postList"); assertThat(pageWrapper.getSize()).isEqualTo(nrOfEntries); assertThat(pageWrapper.getUrl()).isEqualTo(URL.Post.LIST); }