DepartmentService { public List<Department> getAllDepartments() { return departmentRepository.findAll(new Sort(Sort.Direction.ASC, "name")); } @Autowired  DepartmentService(final DepartmentRepository departmentRepository); @Transactional void createDepartment(final Department department); @Transactional void updateDepartment(final Department department); Department getDepartmentById(final Long id); Department getDepartmentByName(final String name); List<Department> getAllDepartments(); Department getDepartmentByCode(final String code); List<Department> getAllDepartmentsByNameLike(final String name); List<Department> getDepartmentsByNames(List<String> names); @Transactional void deleteDepartment(final Department department);  }
@Test public void shouldGetAllDepartments() { Department department1 = new DepartmentBuilder().withName("test1").withCode("test1").build(); Department department2 = new DepartmentBuilder().withName("test2").withCode("test2").build(); when(departmentService.getAllDepartments()).thenReturn(Arrays.asList(department1, department2)); List<Department> list = departmentService.getAllDepartments(); verify(departmentRepository).findAll(new Sort(Sort.Direction.ASC, "name")); assertEquals(list.size(), 2); }