DepartmentService { public Department getDepartmentByName(final String name) { return departmentRepository.findByNameUpperCase(name.toUpperCase()); } @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 shouldGetDepartmentByName() { when(departmentService.getDepartmentByName(anyString())).thenReturn(department); Department expectedDepartment = departmentService.getDepartmentByName("test"); verify(departmentRepository).findByNameUpperCase("test".toUpperCase()); assertTrue(department.equals(expectedDepartment)); }