### Question:
DefaultRoleAccessor implements RoleAccessor { @Override public PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix) throws AlertDatabaseConstraintException { RoleEntity roleEntity = roleRepository.findByRoleName(roleName) .orElseThrow(() -> new AlertDatabaseConstraintException("No role exists with name: " + roleName)); List<PermissionMatrixRelation> permissions = updateRoleOperations(roleEntity, permissionMatrix); return createModelFromPermission(permissions); } @Autowired  DefaultRoleAccessor(RoleRepository roleRepository, UserRoleRepository userRoleRepository, PermissionMatrixRepository permissionMatrixRepository,
        RegisteredDescriptorRepository registeredDescriptorRepository, ConfigContextRepository configContextRepository); @Override Set<UserRoleModel> getRoles(); @Override Set<UserRoleModel> getRoles(Collection<Long> roleIds); @Override boolean doesRoleNameExist(String name); @Override UserRoleModel createRole(String roleName); @Override UserRoleModel createRoleWithPermissions(String roleName, PermissionMatrixModel permissionMatrix); @Override void updateRoleName(Long roleId, String roleName); @Override PermissionMatrixModel updatePermissionsForRole(String roleName, PermissionMatrixModel permissionMatrix); @Override void deleteRole(Long roleId); @Override void updateUserRoles(Long userId, Collection<UserRoleModel> roles); @Override PermissionMatrixModel mergePermissionsForRoles(Collection<String> roleNames); @Override PermissionMatrixModel readPermissionsForRole(Long roleId);  }### Answer:
@Test public void updatePermissionsForRole() throws Exception { final String roleName = "roleName"; final String contextString = "context-test"; final String descriptorName = "descriptorName"; RoleEntity roleEntity = new RoleEntity(roleName, true); roleEntity.setId(1L); ConfigContextEntity configContextEntity = new ConfigContextEntity(contextString); configContextEntity.setId(1L); RegisteredDescriptorEntity registeredDescriptorEntity = new RegisteredDescriptorEntity(descriptorName, 1L); registeredDescriptorEntity.setId(1L); PermissionKey permissionKey = new PermissionKey(contextString, descriptorName); PermissionMatrixModel permissionMatrix = new PermissionMatrixModel(Map.of(permissionKey, AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit())); PermissionMatrixRelation permissionMatrixRelation = new PermissionMatrixRelation(roleEntity.getId(), configContextEntity.getId(), registeredDescriptorEntity.getId(), AccessOperation.READ.getBit() + AccessOperation.WRITE.getBit()); Mockito.when(roleRepository.findByRoleName(Mockito.any())).thenReturn(Optional.of(roleEntity)); mockUpdateRoleOperations(permissionMatrixRelation, configContextEntity, registeredDescriptorEntity); mockCreateModelFromPermission(configContextEntity, registeredDescriptorEntity); DefaultRoleAccessor authorizationUtility = new DefaultRoleAccessor(roleRepository, userRoleRepository, permissionMatrixRepository, registeredDescriptorRepository, configContextRepository); PermissionMatrixModel permissionMatrixModel = authorizationUtility.updatePermissionsForRole(roleName, permissionMatrix); Mockito.verify(permissionMatrixRepository).saveAll(Mockito.any()); assertFalse(permissionMatrixModel.isEmpty()); assertEquals(permissionMatrix, permissionMatrixModel); }