Mocking a method which returns Page interface
@MockBean private PostRepository postRepository; @Autowired private PostService postService; @Test void getAllPostByTitelTest(){ List<Post> post = new ArrayList<>(); Post post = new Post(); post.add(post); Page<Post> pagedResponse = new PageImpl(post); Mockito.when(postRepository.findById(title)).thenReturn(pagedResponse); List<Post> posts = postService.getAllPostByTitel(title); }Related PostSpring Boot pagination - Mockito repositoryHow to deal with Page while unit testing with mockito and JunitHow to mock Page with content data in Unit Test?How to Mock Pageable object using Mockito?
No comments:
Post a Comment