+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import org.apache.commons.lang.NotImplementedException;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.profiles.Alert;
-
-class AlertUtils {
-
- private AlertUtils() {
- // only static stuff
- }
-
- /**
- * Get the matching alert level for the given measure
- */
- static Metric.Level getLevel(Alert alert, Measure measure) {
- if (evaluateAlert(alert, measure, Metric.Level.ERROR)) {
- return Metric.Level.ERROR;
- }
- if (evaluateAlert(alert, measure, Metric.Level.WARN)) {
- return Metric.Level.WARN;
- }
- return Metric.Level.OK;
- }
-
- private static boolean evaluateAlert(Alert alert, Measure measure, Metric.Level alertLevel) {
- String valueToEval = getValueToEval(alert, alertLevel);
- if (StringUtils.isEmpty(valueToEval)) {
- return false;
- }
-
- Comparable criteriaValue = getValueForComparison(alert.getMetric(), valueToEval);
- Comparable measureValue = getMeasureValue(alert, measure);
- if (measureValue != null) {
- return doesReachThresholds(measureValue, criteriaValue, alert);
- }
- return false;
- }
-
- private static boolean doesReachThresholds(Comparable measureValue, Comparable criteriaValue, Alert alert) {
- int comparison = measureValue.compareTo(criteriaValue);
- return !(isNotEquals(comparison, alert)
- || isGreater(comparison, alert)
- || isSmaller(comparison, alert)
- || isEquals(comparison, alert));
- }
-
- private static boolean isNotEquals(int comparison, Alert alert) {
- return alert.isNotEqualsOperator() && comparison == 0;
- }
-
- private static boolean isGreater(int comparison, Alert alert) {
- return alert.isGreaterOperator() && comparison != 1;
- }
-
- private static boolean isSmaller(int comparison, Alert alert) {
- return alert.isSmallerOperator() && comparison != -1;
- }
-
- private static boolean isEquals(int comparison, Alert alert) {
- return alert.isEqualsOperator() && comparison != 0;
- }
-
- private static String getValueToEval(Alert alert, Metric.Level alertLevel) {
- if (alertLevel.equals(Metric.Level.ERROR)) {
- return alert.getValueError();
- } else if (alertLevel.equals(Metric.Level.WARN)) {
- return alert.getValueWarning();
- } else {
- throw new IllegalStateException(alertLevel.toString());
- }
- }
-
- private static Comparable getValueForComparison(Metric metric, String value) {
- if (isADouble(metric)) {
- return Double.parseDouble(value);
- }
- if (isAInteger(metric)) {
- return parseInteger(value);
- }
- if (isAString(metric)) {
- return value;
- }
- if (isABoolean(metric)) {
- return Integer.parseInt(value);
- }
- if (isAWorkDuration(metric)) {
- return Long.parseLong(value);
- }
- throw new NotImplementedException(metric.getType().toString());
- }
-
- private static Comparable<Integer> parseInteger(String value) {
- return value.contains(".") ? Integer.parseInt(value.substring(0, value.indexOf('.'))) : Integer.parseInt(value);
- }
-
- private static Comparable getMeasureValue(Alert alert, Measure measure) {
- Metric metric = alert.getMetric();
- if (isADouble(metric)) {
- return getValue(alert, measure);
- }
- if (isAInteger(metric)) {
- return parseInteger(alert, measure);
- }
- if (isAWorkDuration(metric)) {
- return parseLong(alert, measure);
- }
- if (alert.getPeriod() == null) {
- return getMeasureValueForStringOrBoolean(metric, measure);
- }
- throw new NotImplementedException(metric.getType().toString());
- }
-
- private static Comparable getMeasureValueForStringOrBoolean(Metric metric, Measure measure) {
- if (isAString(metric)) {
- return measure.getData();
- }
- if (isABoolean(metric)) {
- return measure.getValue().intValue();
- }
- throw new NotImplementedException(metric.getType().toString());
- }
-
- private static Comparable<Integer> parseInteger(Alert alert, Measure measure) {
- Double value = getValue(alert, measure);
- return value != null ? value.intValue() : null;
- }
-
- private static Comparable<Long> parseLong(Alert alert, Measure measure) {
- Double value = getValue(alert, measure);
- return value != null ? value.longValue() : null;
- }
-
- private static boolean isADouble(Metric metric) {
- return metric.getType() == Metric.ValueType.FLOAT ||
- metric.getType() == Metric.ValueType.PERCENT ||
- metric.getType() == Metric.ValueType.RATING;
- }
-
- private static boolean isAInteger(Metric metric) {
- return metric.getType() == Metric.ValueType.INT ||
- metric.getType() == Metric.ValueType.MILLISEC;
- }
-
- private static boolean isAString(Metric metric) {
- return metric.getType() == Metric.ValueType.STRING ||
- metric.getType() == Metric.ValueType.LEVEL;
- }
-
- private static boolean isABoolean(Metric metric) {
- return metric.getType() == Metric.ValueType.BOOL;
- }
-
- private static boolean isAWorkDuration(Metric metric) {
- return metric.getType() == Metric.ValueType.WORK_DUR;
- }
-
- private static Double getValue(Alert alert, Measure measure) {
- if (alert.getPeriod() == null) {
- return measure.getValue();
- } else if (alert.getPeriod() == 1) {
- return measure.getVariation1();
- } else if (alert.getPeriod() == 2) {
- return measure.getVariation2();
- } else if (alert.getPeriod() == 3) {
- return measure.getVariation3();
- } else {
- throw new IllegalStateException("Following index period is not allowed : " + Double.toString(alert.getPeriod()));
- }
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import org.sonar.api.batch.Sensor;
-import org.sonar.api.batch.SensorContext;
-import org.sonar.api.batch.fs.FileSystem;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.rule.RulesProfileWrapper;
-
-/**
- * Executed on every module to feed {@link org.sonar.batch.qualitygate.ProjectAlerts}
- */
-public class LegacyQualityGateLoader implements Sensor {
-
- private final FileSystem fs;
- private final RulesProfile qProfile;
- private final ProjectAlerts projectAlerts;
-
- public LegacyQualityGateLoader(FileSystem fs, RulesProfile qProfile, ProjectAlerts projectAlerts) {
- this.fs = fs;
- this.qProfile = qProfile;
- this.projectAlerts = projectAlerts;
- }
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @Override
- public void analyse(Project module, SensorContext context) {
- for (String lang : fs.languages()) {
- RulesProfile profile = qProfile instanceof RulesProfileWrapper ? ((RulesProfileWrapper) qProfile).getProfileByLanguage(lang) : qProfile;
- if (profile != null) {
- projectAlerts.addAll(profile.getAlerts());
- }
- }
- }
-
- @Override
- public String toString() {
- return "Quality gate loader";
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.*;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.i18n.I18n;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.profiles.Alert;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.Durations;
-import org.sonar.core.timemachine.Periods;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Locale;
-import java.util.Set;
-
-public class LegacyQualityGateVerifier implements Decorator {
-
- private static final String VARIATION_METRIC_PREFIX = "new_";
- private static final String VARIATION = "variation";
-
- private final Snapshot snapshot;
- private final Periods periods;
- private final I18n i18n;
- private final Durations durations;
- private ProjectAlerts projectAlerts;
-
- public LegacyQualityGateVerifier(Snapshot snapshot, ProjectAlerts projectAlerts, Periods periods, I18n i18n, Durations durations) {
- this.snapshot = snapshot;
- this.projectAlerts = projectAlerts;
- this.periods = periods;
- this.i18n = i18n;
- this.durations = durations;
- }
-
- @DependedUpon
- public Metric generatesAlertStatus() {
- return CoreMetrics.ALERT_STATUS;
- }
-
- @DependsUpon
- public String dependsOnVariations() {
- return DecoratorBarriers.END_OF_TIME_MACHINE;
- }
-
- @DependsUpon
- public Collection<Metric> dependsUponMetrics() {
- Set<Metric> metrics = Sets.newHashSet();
- for (Alert alert : projectAlerts.all()) {
- metrics.add(alert.getMetric());
- }
- return metrics;
- }
-
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- public void decorate(final Resource resource, final DecoratorContext context) {
- if (ResourceUtils.isRootProject(resource) && !projectAlerts.all().isEmpty() && context.getMeasure(CoreMetrics.ALERT_STATUS) == null) {
- checkProjectAlerts(context);
- }
- }
-
- private void checkProjectAlerts(DecoratorContext context) {
- Metric.Level globalLevel = Metric.Level.OK;
- List<String> labels = Lists.newArrayList();
-
- for (Alert alert : projectAlerts.all()) {
- Measure measure = context.getMeasure(alert.getMetric());
- if (measure != null) {
- Metric.Level level = AlertUtils.getLevel(alert, measure);
-
- measure.setAlertStatus(level);
- String text = getText(alert, level);
- if (!StringUtils.isBlank(text)) {
- measure.setAlertText(text);
- labels.add(text);
- }
-
- context.saveMeasure(measure);
-
- if (Metric.Level.WARN == level && globalLevel != Metric.Level.ERROR) {
- globalLevel = Metric.Level.WARN;
-
- } else if (Metric.Level.ERROR == level) {
- globalLevel = Metric.Level.ERROR;
- }
- }
- }
-
- Measure globalMeasure = new Measure(CoreMetrics.ALERT_STATUS, globalLevel);
- globalMeasure.setAlertStatus(globalLevel);
- globalMeasure.setAlertText(StringUtils.join(labels, ", "));
- context.saveMeasure(globalMeasure);
- }
-
- private String getText(Alert alert, Metric.Level level) {
- if (level == Metric.Level.OK) {
- return null;
- }
- return getAlertLabel(alert, level);
- }
-
- private String getAlertLabel(Alert alert, Metric.Level level) {
- Integer alertPeriod = alert.getPeriod();
- String metric = i18n.message(Locale.ENGLISH, "metric." + alert.getMetric().getKey() + ".name", alert.getMetric().getName());
-
- StringBuilder stringBuilder = new StringBuilder();
- stringBuilder.append(metric);
-
- if (alertPeriod != null && !alert.getMetric().getKey().startsWith(VARIATION_METRIC_PREFIX)) {
- String variation = i18n.message(Locale.ENGLISH, VARIATION, VARIATION).toLowerCase();
- stringBuilder.append(" ").append(variation);
- }
-
- stringBuilder
- .append(" ").append(alert.getOperator()).append(" ")
- .append(alertValue(alert, level));
-
- if (alertPeriod != null) {
- stringBuilder.append(" ").append(periods.label(snapshot, alertPeriod));
- }
-
- return stringBuilder.toString();
- }
-
- private String alertValue(Alert alert, Metric.Level level) {
- String value = level.equals(Metric.Level.ERROR) ? alert.getValueError() : alert.getValueWarning();
- if (alert.getMetric().getType().equals(Metric.ValueType.WORK_DUR)) {
- return durations.format(Locale.ENGLISH, Duration.create(Long.parseLong(value)), Durations.DurationFormat.SHORT);
- } else {
- return value;
- }
- }
-
- @Override
- public String toString() {
- return getClass().getSimpleName();
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import com.google.common.collect.Sets;
-import org.sonar.api.BatchComponent;
-import org.sonar.api.profiles.Alert;
-
-import java.util.Collection;
-import java.util.Set;
-
-/**
- * Lists the alerts enabled on the current project.
- */
-public class ProjectAlerts implements BatchComponent {
-
- private final Set<Alert> alerts = Sets.newHashSet();
-
- void addAll(Collection<Alert> alerts) {
- this.alerts.addAll(alerts);
- }
-
- Set<Alert> all() {
- return alerts;
- }
-
-}
import org.sonar.batch.issue.ignore.scanner.IssueExclusionsRegexpScanner;
import org.sonar.batch.phases.PhaseExecutor;
import org.sonar.batch.phases.PhasesTimeProfiler;
-import org.sonar.batch.qualitygate.LegacyQualityGateLoader;
-import org.sonar.batch.qualitygate.LegacyQualityGateVerifier;
import org.sonar.batch.qualitygate.QualityGateProvider;
import org.sonar.batch.qualitygate.QualityGateVerifier;
import org.sonar.batch.rule.*;
// quality gates
new QualityGateProvider(),
QualityGateVerifier.class,
- LegacyQualityGateLoader.class,
- LegacyQualityGateVerifier.class,
// rules
ModuleQProfiles.class,
import org.sonar.batch.issue.*;
import org.sonar.batch.phases.GraphPersister;
import org.sonar.batch.profiling.PhasesSumUpTimeProfiler;
-import org.sonar.batch.qualitygate.ProjectAlerts;
import org.sonar.batch.rule.RulesProvider;
import org.sonar.batch.scan.filesystem.InputFileCache;
import org.sonar.batch.scan.maven.FakeMavenPluginExecutor;
// technical debt
new DebtModelProvider(),
- // quality gates
- ProjectAlerts.class,
-
// rules
new RulesProvider(),
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-
-package org.sonar.batch.qualitygate;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.profiles.Alert;
-
-public class AlertUtilsTest {
- private Metric metric;
- private Measure measure;
- private Alert alert;
-
- @Before
- public void setup() {
- metric = new Metric.Builder("test-metric", "name", Metric.ValueType.FLOAT).create();
- measure = new Measure();
- measure.setMetric(metric);
- alert = new Alert();
- }
-
- @Test
- public void testInputNumbers() {
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_SMALLER);
- alert.setMetric(metric);
-
- try {
- metric.setType(Metric.ValueType.FLOAT);
- alert.setValueError("20");
- AlertUtils.getLevel(alert, measure);
- } catch (NumberFormatException ex) {
- Assert.fail();
- }
-
- try {
- metric.setType(Metric.ValueType.INT);
- alert.setValueError("20.1");
- AlertUtils.getLevel(alert, measure);
- } catch (NumberFormatException ex) {
- Assert.fail();
- }
-
- try {
- metric.setType(Metric.ValueType.PERCENT);
- alert.setValueError("20.1");
- AlertUtils.getLevel(alert, measure);
- } catch (NumberFormatException ex) {
- Assert.fail();
- }
- }
-
- @Test
- public void testEquals() {
-
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("10.2");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.1");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- metric.setType(Metric.ValueType.STRING);
- measure.setData("TEST");
- measure.setValue(null);
-
- alert.setValueError("TEST");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("TEST2");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- }
-
- @Test
- public void testNotEquals() {
-
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_NOT_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("10.2");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.1");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- metric.setType(Metric.ValueType.STRING);
- measure.setData("TEST");
- measure.setValue(null);
-
- alert.setValueError("TEST");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("TEST2");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- }
-
- @Test
- public void testGreater() {
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_GREATER);
- alert.setMetric(metric);
-
- alert.setValueError("10.1");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.3");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testSmaller() {
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_SMALLER);
- alert.setMetric(metric);
-
- alert.setValueError("10.1");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.3");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testPercent() {
- metric.setType(Metric.ValueType.PERCENT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("10.2");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testFloat() {
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("10.2");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testInteger() {
- metric.setType(Metric.ValueType.INT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("10");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.2");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testLevel() {
- metric.setType(Metric.ValueType.LEVEL);
- measure.setData(Metric.Level.ERROR.toString());
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError(Metric.Level.ERROR.toString());
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError(Metric.Level.OK.toString());
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- alert.setOperator(Alert.OPERATOR_NOT_EQUALS);
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testBooleans() {
- metric.setType(Metric.ValueType.BOOL);
- measure.setValue(0d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("1");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("0");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setOperator(Alert.OPERATOR_NOT_EQUALS);
- alert.setValueError("1");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("0");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void test_work_duration() {
- metric.setType(Metric.ValueType.WORK_DUR);
- measure.setValue(60.0d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("60");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
- }
-
- @Test
- public void testErrorAndWarningLevel() {
- metric.setType(Metric.ValueType.FLOAT);
- measure.setValue(10.2d);
- alert.setOperator(Alert.OPERATOR_EQUALS);
- alert.setMetric(metric);
-
- alert.setValueError("10.2");
- Assert.assertEquals(Metric.Level.ERROR, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.1");
- Assert.assertEquals(Metric.Level.OK, AlertUtils.getLevel(alert, measure));
-
- alert.setValueError("10.3");
- alert.setValueWarning("10.2");
- Assert.assertEquals(Metric.Level.WARN, AlertUtils.getLevel(alert, measure));
- }
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import com.google.common.collect.Lists;
-import org.junit.Test;
-import org.sonar.api.batch.fs.internal.DefaultFileSystem;
-import org.sonar.api.profiles.Alert;
-import org.sonar.api.profiles.RulesProfile;
-import org.sonar.api.resources.Project;
-import org.sonar.batch.rule.RulesProfileWrapper;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class LegacyQualityGateLoaderTest {
-
- DefaultFileSystem fs = new DefaultFileSystem();
- RulesProfileWrapper qProfile = mock(RulesProfileWrapper.class);
- ProjectAlerts alerts = new ProjectAlerts();
- LegacyQualityGateLoader loader = new LegacyQualityGateLoader(fs, qProfile, alerts);
-
- @Test
- public void should_always_be_executed() throws Exception {
- assertThat(loader.shouldExecuteOnProject(new Project("struts"))).isTrue();
- }
-
- @Test
- public void test_toString() throws Exception {
- assertThat(loader.toString()).isEqualTo("Quality gate loader");
- }
-
- @Test
- public void register_project_alerts() throws Exception {
- fs.addLanguages("java", "php");
-
- RulesProfile javaProfile = new RulesProfile();
- javaProfile.setAlerts(Lists.newArrayList(new Alert()));
- when(qProfile.getProfileByLanguage("java")).thenReturn(javaProfile);
-
- loader.analyse(null, null);
-
- assertThat(alerts.all()).hasSize(1);
- }
-}
+++ /dev/null
-
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import com.google.common.collect.Lists;
-import org.apache.commons.lang.NotImplementedException;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.ArgumentMatcher;
-import org.sonar.api.batch.DecoratorBarriers;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.i18n.I18n;
-import org.sonar.api.measures.CoreMetrics;
-import org.sonar.api.measures.Measure;
-import org.sonar.api.measures.Metric;
-import org.sonar.api.profiles.Alert;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.test.IsMeasure;
-import org.sonar.api.utils.Duration;
-import org.sonar.api.utils.Durations;
-import org.sonar.core.timemachine.Periods;
-
-import java.util.Locale;
-
-import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyString;
-import static org.mockito.Matchers.argThat;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class LegacyQualityGateVerifierTest {
-
- LegacyQualityGateVerifier verifier;
- DecoratorContext context;
- ProjectAlerts projectAlerts;
-
- Measure measureClasses;
- Measure measureCoverage;
- Measure measureComplexity;
- Resource project;
- Snapshot snapshot;
- Periods periods;
- I18n i18n;
- Durations durations;
-
- @Before
- public void before() {
- context = mock(DecoratorContext.class);
- periods = mock(Periods.class);
- i18n = mock(I18n.class);
- durations = mock(Durations.class);
- when(i18n.message(any(Locale.class), eq("variation"), eq("variation"))).thenReturn("variation");
-
- measureClasses = new Measure(CoreMetrics.CLASSES, 20d);
- measureCoverage = new Measure(CoreMetrics.COVERAGE, 35d);
- measureComplexity = new Measure(CoreMetrics.COMPLEXITY, 50d);
-
- when(context.getMeasure(CoreMetrics.CLASSES)).thenReturn(measureClasses);
- when(context.getMeasure(CoreMetrics.COVERAGE)).thenReturn(measureCoverage);
- when(context.getMeasure(CoreMetrics.COMPLEXITY)).thenReturn(measureComplexity);
-
- snapshot = mock(Snapshot.class);
- projectAlerts = new ProjectAlerts();
- verifier = new LegacyQualityGateVerifier(snapshot, projectAlerts, periods, i18n, durations);
- project = new Project("foo");
- }
-
- @Test
- public void should_always_be_executed() {
- assertThat(verifier.shouldExecuteOnProject(new Project("foo"))).isTrue();
- }
-
- @Test
- public void test_toString() {
- assertThat(verifier.toString()).isEqualTo("LegacyQualityGateVerifier");
- }
-
- @Test
- public void generates_alert_status() {
- assertThat(verifier.generatesAlertStatus()).isEqualTo(CoreMetrics.ALERT_STATUS);
- }
-
- @Test
- public void depends_on_variations() {
- assertThat(verifier.dependsOnVariations()).isEqualTo(DecoratorBarriers.END_OF_TIME_MACHINE);
- }
-
- @Test
- public void depends_upon_metrics() {
- projectAlerts.addAll(Lists.newArrayList(new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20")));
- assertThat(verifier.dependsUponMetrics()).containsOnly(CoreMetrics.CLASSES);
- }
-
- @Test
- public void ok_when_no_alerts() {
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"),
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_GREATER, null, "35.0")));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(new IsMeasure(CoreMetrics.ALERT_STATUS, Metric.Level.OK.toString())));
- verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
- verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
- }
-
- @Test
- public void not_run_when_alert_status_already_set() {
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"),
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_GREATER, null, "35.0")));
- when(context.getMeasure(CoreMetrics.ALERT_STATUS)).thenReturn(mock(Measure.class));
-
- verifier.decorate(project, context);
-
- verify(context, never()).saveMeasure(argThat(new IsMeasure(CoreMetrics.ALERT_STATUS, Metric.Level.OK.toString())));
- verify(context, never()).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
- verify(context, never()).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
- }
-
- @Test
- public void check_root_modules_only() {
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"),
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_GREATER, null, "35.0")));
-
- verifier.decorate(File.create("src/Foo.php"), context);
-
- verify(context, never()).saveMeasure(any(Measure.class));
- }
-
- @Test
- public void generate_warnings() {
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "100"),
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_SMALLER, null, "95.0"))); // generates warning because coverage 35% < 95%
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, null)));
-
- verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
- verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.WARN)));
-
- }
-
- @Test
- public void globalStatusShouldBeErrorIfWarningsAndErrors() {
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_SMALLER, null, "100"), // generates warning because classes 20 < 100
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_SMALLER, "50.0", "80.0"))); // generates error because coverage 35% < 50%
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, null)));
-
- verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
- verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.ERROR)));
- }
-
- @Test
- public void globalLabelShouldAggregateAllLabels() {
- when(i18n.message(any(Locale.class), eq("metric.classes.name"), anyString())).thenReturn("Classes");
- when(i18n.message(any(Locale.class), eq("metric.coverage.name"), anyString())).thenReturn("Coverages");
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_SMALLER, null, "10000"), // there are 20 classes, error threshold is higher =>
- // alert
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_SMALLER, "50.0", "80.0"))); // coverage is 35%, warning threshold is higher =>
- // alert
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "Classes < 10000, Coverages < 50.0")));
- }
-
- @Test
- public void alertLabelUsesL10nMetricName() {
- Metric metric = new Metric.Builder("rating", "Rating", Metric.ValueType.INT).create();
-
- // metric name is declared in l10n bundle
- when(i18n.message(any(Locale.class), eq("metric.rating.name"), anyString())).thenReturn("THE RATING");
-
- when(context.getMeasure(metric)).thenReturn(new Measure(metric, 4d));
- projectAlerts.addAll(Lists.newArrayList(new Alert(null, metric, Alert.OPERATOR_SMALLER, "10", null)));
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "THE RATING < 10")));
- }
-
- @Test
- public void alertLabelUsesMetricNameIfMissingL10nBundle() {
- // the third argument is Metric#getName()
- when(i18n.message(any(Locale.class), eq("metric.classes.name"), eq("Classes"))).thenReturn("Classes");
- projectAlerts.addAll(Lists.newArrayList(
- // there are 20 classes, error threshold is higher => alert
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_SMALLER, "10000", null)
- ));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "Classes < 10000")));
- }
-
- @Test
- public void shouldBeOkIfPeriodVariationIsEnough() {
- measureClasses.setVariation1(0d);
- measureCoverage.setVariation2(50d);
- measureComplexity.setVariation3(2d);
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "10", 1), // ok because no variation
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_SMALLER, null, "40.0", 2), // ok because coverage increases of 50%, which is more
- // than 40%
- new Alert(null, CoreMetrics.COMPLEXITY, Alert.OPERATOR_GREATER, null, "5", 3) // ok because complexity increases of 2, which is less
- // than 5
- ));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null)));
-
- verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
- verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.OK)));
- verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.OK)));
- }
-
- @Test
- public void shouldGenerateWarningIfPeriodVariationIsNotEnough() {
- measureClasses.setVariation1(40d);
- measureCoverage.setVariation2(5d);
- measureComplexity.setVariation3(70d);
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "30", 1), // generates warning because classes increases of 40,
- // which is greater than 30
- new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_SMALLER, null, "10.0", 2), // generates warning because coverage increases of 5%,
- // which is smaller than 10%
- new Alert(null, CoreMetrics.COMPLEXITY, Alert.OPERATOR_GREATER, null, "60", 3) // generates warning because complexity increases of
- // 70, which is smaller than 60
- ));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, null)));
-
- verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.WARN)));
- verify(context).saveMeasure(argThat(hasLevel(measureCoverage, Metric.Level.WARN)));
- verify(context).saveMeasure(argThat(hasLevel(measureComplexity, Metric.Level.WARN)));
- }
-
- @Test
- public void shouldBeOkIfVariationIsNull() {
- measureClasses.setVariation1(null);
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "10", 1)));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null)));
- verify(context).saveMeasure(argThat(hasLevel(measureClasses, Metric.Level.OK)));
- }
-
- @Test
- public void shouldVariationPeriodValueCouldBeUsedForRatingMetric() {
- Metric ratingMetric = new Metric.Builder("key_rating_metric", "Rating metric", Metric.ValueType.RATING).create();
- Measure measureRatingMetric = new Measure(ratingMetric, 150d);
- measureRatingMetric.setVariation1(50d);
- when(context.getMeasure(ratingMetric)).thenReturn(measureRatingMetric);
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, ratingMetric, Alert.OPERATOR_GREATER, null, "100", 1)
- ));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.OK, null)));
- verify(context).saveMeasure(argThat(hasLevel(measureRatingMetric, Metric.Level.OK)));
- }
-
- @Test(expected = IllegalStateException.class)
- public void shouldAllowOnlyVariationPeriodOneGlobalPeriods() {
- measureClasses.setVariation4(40d);
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "30", 4)
- ));
-
- verifier.decorate(project, context);
- }
-
- @Test(expected = NotImplementedException.class)
- public void shouldNotAllowPeriodVariationAlertOnStringMetric() {
- Measure measure = new Measure(CoreMetrics.SCM_AUTHORS_BY_LINE, 100d);
- measure.setVariation1(50d);
- when(context.getMeasure(CoreMetrics.SCM_AUTHORS_BY_LINE)).thenReturn(measure);
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.SCM_AUTHORS_BY_LINE, Alert.OPERATOR_GREATER, null, "30", 1)
- ));
-
- verifier.decorate(project, context);
- }
-
- @Test
- public void shouldLabelAlertContainsPeriod() {
- measureClasses.setVariation1(40d);
-
- when(i18n.message(any(Locale.class), eq("metric.classes.name"), anyString())).thenReturn("Classes");
- when(periods.label(snapshot, 1)).thenReturn("since someday");
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "30", 1) // generates warning because classes increases of 40,
- // which is greater than 30
- ));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, "Classes variation > 30 since someday")));
- }
-
- @Test
- public void shouldLabelAlertForNewMetricDoNotContainsVariationWord() {
- Metric newMetric = new Metric.Builder("new_metric_key", "New Metric", Metric.ValueType.INT).create();
- Measure measure = new Measure(newMetric, 15d);
- measure.setVariation1(50d);
- when(context.getMeasure(newMetric)).thenReturn(measure);
- measureClasses.setVariation1(40d);
-
- when(i18n.message(any(Locale.class), eq("metric.new_metric_key.name"), anyString())).thenReturn("New Measure");
- when(periods.label(snapshot, 1)).thenReturn("since someday");
-
- projectAlerts.addAll(Lists.newArrayList(
- new Alert(null, newMetric, Alert.OPERATOR_GREATER, null, "30", 1) // generates warning because classes increases of 40, which is
- // greater than 30
- ));
-
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.WARN, "New Measure > 30 since someday")));
- }
-
- @Test
- public void alert_on_work_duration() {
- Metric metric = new Metric.Builder("tech_debt", "Debt", Metric.ValueType.WORK_DUR).create();
-
- // metric name is declared in l10n bundle
- when(i18n.message(any(Locale.class), eq("metric.tech_debt.name"), anyString())).thenReturn("The Debt");
- when(durations.format(any(Locale.class), eq(Duration.create(3600L)), eq(Durations.DurationFormat.SHORT))).thenReturn("1h");
-
- when(context.getMeasure(metric)).thenReturn(new Measure(metric, 1800d));
- projectAlerts.addAll(Lists.newArrayList(new Alert(null, metric, Alert.OPERATOR_SMALLER, "3600", null)));
- verifier.decorate(project, context);
-
- verify(context).saveMeasure(argThat(matchesMetric(CoreMetrics.ALERT_STATUS, Metric.Level.ERROR, "The Debt < 1h")));
- }
-
- private ArgumentMatcher<Measure> matchesMetric(final Metric metric, final Metric.Level alertStatus, final String alertText) {
- return new ArgumentMatcher<Measure>() {
- @Override
- public boolean matches(Object arg) {
- boolean result = ((Measure) arg).getMetric().equals(metric) && ((Measure) arg).getAlertStatus() == alertStatus;
- if (result && alertText != null) {
- result = alertText.equals(((Measure) arg).getAlertText());
- }
- return result;
- }
- };
- }
-
- private ArgumentMatcher<Measure> hasLevel(final Measure measure, final Metric.Level alertStatus) {
- return new ArgumentMatcher<Measure>() {
- @Override
- public boolean matches(Object arg) {
- return arg == measure && ((Measure) arg).getAlertStatus().equals(alertStatus);
- }
- };
- }
-
-}
+++ /dev/null
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2014 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube 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.
- *
- * SonarQube 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.
- */
-package org.sonar.batch.qualitygate;
-
-import com.google.common.collect.Lists;
-import org.junit.Test;
-import org.sonar.api.profiles.Alert;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class ProjectAlertsTest {
- @Test
- public void test() throws Exception {
- ProjectAlerts alerts = new ProjectAlerts();
- assertThat(alerts.all()).isEmpty();
-
- alerts.addAll(Lists.newArrayList(new Alert()));
- assertThat(alerts.all()).hasSize(1);
- }
-}