AlterQueryServiceCommand extends SingleGfshCommand { @Override public boolean updateConfigForGroup(String group, CacheConfig config, Object configObject) { if (configObject instanceof QueryConfigService) { List<CacheElement> elements = config.getCustomCacheElements(); elements.removeIf(e -> e instanceof QueryConfigService); elements.add((QueryConfigService) configObject); return true; } return false; }  @CliCommand(value = COMMAND_NAME, help = COMMAND_HELP) @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER, operation = ResourcePermission.Operation.MANAGE) ResultModel execute(
      @CliOption(key = AUTHORIZER_NAME, help = METHOD_AUTHORIZER_NAME_HELP,
          mandatory = true) String methodAuthorizerName,
      @CliOption(key = AUTHORIZER_PARAMETERS, help = AUTHORIZER_PARAMETERS_HELP,
          optionContext = "splittingRegex=" + SPLITTING_REGEX) String[] authorizerParameters,
      @CliOption(key = FORCE_UPDATE, help = FORCE_UPDATE_HELP, specifiedDefaultValue = "true",
          unspecifiedDefaultValue = "false") boolean forceUpdate); @Override boolean updateConfigForGroup(String group, CacheConfig config, Object configObject); static final String PARTIAL_FAILURE_MESSAGE; }
@Test public void updateConfigForGroupReplacesExistingElementWithNewElement() { CacheConfig mockCacheConfig = mock(CacheConfig.class); QueryConfigService newConfigService = mock(QueryConfigService.class); QueryConfigService existingConfigService = mock(QueryConfigService.class); List<CacheElement> elements = new ArrayList<>(); elements.add(existingConfigService); when(mockCacheConfig.getCustomCacheElements()).thenReturn(elements); assertThat(elements.size()).isEqualTo(1); assertThat(command.updateConfigForGroup(null, mockCacheConfig, newConfigService)).isTrue(); assertThat(elements.size()).isEqualTo(1); assertThat(elements.get(0)).isSameAs(newConfigService); }