DeptDesigService { public DeptDesig findByDepartmentAndDesignation(final Long id, final Long designationId) { return deptDesigRepository.findByDepartment_IdAndDesignation_Id(id, designationId); } @Autowired  DeptDesigService(final DeptDesigRepository deptDesigRepository); DeptDesig findById(final Long id); DeptDesig findByDepartmentAndDesignation(final Long id, final Long designationId); List<Designation> getDesignationsByDepartment(final Long departmentId); @Transactional void create(final DeptDesig deptDesig); @Transactional void update(final DeptDesig deptDesig); @Transactional void delete(final DeptDesig deptDesig);  }
@Test public void getByDeptAndDesig() { when( deptDesigRepository.findByDepartment_IdAndDesignation_Id(department.getId(), designation.getId())).thenReturn(deptDesig); final Integer sancPosts = deptDesigService.findByDepartmentAndDesignation(department.getId(), designation.getId()).getSanctionedPosts(); assertEquals(sancPosts, Integer.valueOf(5)); }