@Override
  public ValidationResult setProperty(
      final ControllerService service, final PropertyDescriptor property, final String value) {
    final MockStateManager serviceStateManager =
        controllerServiceStateManagers.get(service.getIdentifier());
    if (serviceStateManager == null) {
      throw new IllegalStateException(
          "Controller service "
              + service
              + " has not been added to this TestRunner via the #addControllerService method");
    }

    final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
    final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
    final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);

    final ValidationContext validationContext =
        new MockValidationContext(context, serviceStateManager)
            .getControllerServiceValidationContext(service);
    final ValidationResult validationResult = property.validate(value, validationContext);

    updatedProps.put(property, value);
    configuration.setProperties(updatedProps);

    return validationResult;
  }
  @Override
  public void enableControllerService(final ControllerService service) {
    final ControllerServiceConfiguration configuration =
        context.getConfiguration(service.getIdentifier());
    if (configuration == null) {
      throw new IllegalArgumentException("Controller Service " + service + " is not known");
    }

    if (configuration.isEnabled()) {
      throw new IllegalStateException(
          "Cannot enable Controller Service " + service + " because it is not disabled");
    }

    try {
      final ConfigurationContext configContext =
          new MockConfigurationContext(service, configuration.getProperties(), context);
      ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, service, configContext);
    } catch (final InvocationTargetException ite) {
      ite.getCause().printStackTrace();
      Assert.fail("Failed to enable Controller Service " + service + " due to " + ite.getCause());
    } catch (final Exception e) {
      e.printStackTrace();
      Assert.fail("Failed to enable Controller Service " + service + " due to " + e);
    }

    configuration.setEnabled(true);
  }
  @Override
  public boolean isControllerServiceEnabled(final ControllerService service) {
    final ControllerServiceConfiguration configuration =
        context.getConfiguration(service.getIdentifier());
    if (configuration == null) {
      throw new IllegalArgumentException("Controller Service " + service + " is not known");
    }

    return configuration.isEnabled();
  }
  private ControllerServiceConfiguration getConfigToUpdate(final ControllerService service) {
    final ControllerServiceConfiguration configuration =
        context.getConfiguration(service.getIdentifier());
    if (configuration == null) {
      throw new IllegalArgumentException("Controller Service " + service + " is not known");
    }

    if (configuration.isEnabled()) {
      throw new IllegalStateException(
          "Controller service " + service + " cannot be modified because it is not disabled");
    }

    return configuration;
  }
  @Override
  public void disableControllerService(final ControllerService service) {
    final ControllerServiceConfiguration configuration =
        context.getConfiguration(service.getIdentifier());
    if (configuration == null) {
      throw new IllegalArgumentException("Controller Service " + service + " is not known");
    }

    if (!configuration.isEnabled()) {
      throw new IllegalStateException(
          "Controller service " + service + " cannot be disabled because it is not enabled");
    }

    try {
      ReflectionUtils.invokeMethodsWithAnnotation(OnDisabled.class, service);
    } catch (final Exception e) {
      e.printStackTrace();
      Assert.fail("Failed to disable Controller Service " + service + " due to " + e);
    }

    configuration.setEnabled(false);
  }
 @Override
 public void setAnnotationData(final ControllerService service, final String annotationData) {
   final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
   configuration.setAnnotationData(annotationData);
 }