Tuesday, August 23, 2022

Mocking a method which returns Page interface

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 Post 
Spring Boot pagination - Mockito repository
How to deal with Page while unit testing with mockito and Junit
How to mock Page with content data in Unit Test?
How to Mock Pageable object using Mockito?

No comments:

Post a Comment