private static final Set<String> AUTHORIZED_CATEGORIES = ImmutableSet.of("Version", "Other");
private static final String AUTHORIZED_CATEGORIES_INLINED = Joiner.on(", ").join(AUTHORIZED_CATEGORIES);
+ private EventValidator() {
+ // prevent instantiation
+ }
+
static Consumer<EventDto> checkModifiable() {
return event -> checkArgument(AUTHORIZED_CATEGORIES.contains(event.getCategory()),
"Event of category '%s' cannot be modified. Authorized categories: %s",
resetRequest.getKeys().forEach(key -> {
SettingData data = new SettingData(key, emptyList(), component.orElse(null));
ImmutableList.of(validations.scope(), validations.qualifier())
- .forEach(validation -> validation.validate(data));
+ .forEach(validation -> validation.accept(data));
});
List<String> keys = getKeys(resetRequest);
checkValueIsSet(request);
SettingData settingData = new SettingData(request.getKey(), valuesFromRequest(request), component.orElse(null));
ImmutableList.of(validations.scope(), validations.qualifier(), validations.valueType())
- .forEach(validation -> validation.validate(settingData));
+ .forEach(validation -> validation.accept(settingData));
}
- private void validatePropertySet(SetRequest request, @Nullable PropertyDefinition definition) {
+ private static void validatePropertySet(SetRequest request, @Nullable PropertyDefinition definition) {
checkRequest(definition != null, "Setting '%s' is undefined", request.getKey());
checkRequest(PropertyType.PROPERTY_SET.equals(definition.type()), "Parameter '%s' is used for setting of property set type only", PARAM_FIELD_VALUES);
import java.util.List;
import java.util.Locale;
+import java.util.function.Consumer;
import java.util.stream.Collectors;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
this.i18n = i18n;
}
- public SettingValidation scope() {
+ public Consumer<SettingData> scope() {
return data -> {
PropertyDefinition definition = definitions.get(data.key);
checkRequest(data.component != null || definition == null || definition.global() || isGlobal(definition),
};
}
- public SettingValidation qualifier() {
+ public Consumer<SettingData> qualifier() {
return data -> {
String qualifier = data.component == null ? "" : data.component.qualifier();
PropertyDefinition definition = definitions.get(data.key);
};
}
- public SettingValidation valueType() {
+ public Consumer<SettingData> valueType() {
return new ValueTypeValidation();
}
return !definition.global() && definition.qualifiers().isEmpty();
}
- @FunctionalInterface
- public interface SettingValidation {
- void validate(SettingData data);
- }
-
public static class SettingData {
private final String key;
private final List<String> values;
}
}
- private class ValueTypeValidation implements SettingValidation {
-
+ private class ValueTypeValidation implements Consumer<SettingData> {
@Override
- public void validate(SettingData data) {
+ public void accept(SettingData data) {
PropertyDefinition definition = definitions.get(data.key);
if (definition == null) {
return;
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+@ParametersAreNonnullByDefault
+package org.sonarqube.ws.client.license;
+
+import javax.annotation.ParametersAreNonnullByDefault;
+
public void other_category_by_default() {
CreateEventRequest result = underTest.setAnalysis("P1").setName("name").build();
- assertThat(OTHER.equals(result.getCategory()));
+ assertThat(OTHER).isEqualTo(result.getCategory());
}
@Test