### Question:
ProductService { public Iterable<Product> findProductsByCategoryId(long categoryId) { return categoryRepository.findById(categoryId) .map(productRepository::findAllByCategory) .orElse(Collections.emptyList()); }  Optional<Product> findProductById(final long productId); Iterable<Product> findProductsByCategoryId(long categoryId);  }### Answer:
@Test public void shouldFindAllTheProductsByTheCategoryId() { long categoryId = 1; Category category = TestDataFactory.getCategory(categoryId); List<Product> products = TestDataFactory.getProductList(5, category); when(categoryRepository.findById(categoryId)).thenReturn(Optional.of(category)); when(productRepository.findAllByCategory(category)).thenReturn(products); assertThat(productService.findProductsByCategoryId(categoryId)).isEqualTo(products); }