DepartmentService { public Department getDepartmentById(final Long id) { return departmentRepository.findOne(id); } @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 shouldGetDepartmentById() { department.setId(1l); when(departmentService.getDepartmentById(anyLong())).thenReturn(department); Department expectedDepartment = departmentService.getDepartmentById(1l); verify(departmentRepository).findOne(1l); assertEquals(expectedDepartment, department); }