### Question:
CategorySpecifications { public Specification<Category> byUser(User user) { return (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get(Category_.masterCategory).get(MasterCategory_.user), user); }  Specification<Category> byUser(User user);  }### Answer:
@Test public void byUser() { User user = userRepository.save(new User("Bob", "€")); MasterCategory mcMonthly = masterCategoryRepository.save(new MasterCategory().setName("Monthly").setUser(user)); MasterCategory mcSavings = masterCategoryRepository.save(new MasterCategory().setName("Savings").setUser(user)); categoryRepository.saveAll(asList( new Category().setName("Rent").setMasterCategory(mcMonthly), new Category().setName("Internet").setMasterCategory(mcMonthly), new Category().setName("Rainy Day Funds").setMasterCategory(mcSavings), new Category().setName("Christmas").setMasterCategory(mcSavings) )); Specification<Category> specification = testSubject.byUser(user); List<Category> categories = categoryRepository.findAll(specification); assertThat(categories).extracting("name").containsExactlyInAnyOrder("Rent", "Internet", "Rainy Day Funds", "Christmas"); }