diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-11 19:08:26 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-11 19:08:26 +0200 |
commit | b0d71975c7f6840acfcfc64c83a2de59889170fc (patch) | |
tree | 4d93f0d34afda2c1a633665d3532357c17005e1d /plugins | |
parent | f09e68315cb2c97f6944ad07237902981d97add3 (diff) | |
download | sonarqube-b0d71975c7f6840acfcfc64c83a2de59889170fc.tar.gz sonarqube-b0d71975c7f6840acfcfc64c83a2de59889170fc.zip |
Fix quality flaws
Diffstat (limited to 'plugins')
2 files changed, 26 insertions, 16 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java index b03d894c863..197dfb3fd41 100644 --- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java +++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java @@ -21,11 +21,7 @@ package org.sonar.plugins.core.sensors; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorBarriers; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; +import org.sonar.api.batch.*; import org.sonar.api.database.model.Snapshot; import org.sonar.api.i18n.I18n; import org.sonar.api.measures.CoreMetrics; @@ -143,7 +139,7 @@ public class CheckAlertThresholds implements Decorator { stringBuilder.append(metric); if (alertPeriod != null && !alert.getMetric().getKey().startsWith(VARIATION_METRIC_PREFIX)) { - String variation = i18n.message(getLocale(), "variation", null).toLowerCase(); + String variation = i18n.message(getLocale(), "variation", "variation").toLowerCase(); stringBuilder.append(" ").append(variation); } diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java index b6d2942d146..9a48abfd4c9 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; +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; @@ -42,13 +43,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; -import static org.junit.Assert.assertFalse; +import static com.google.common.collect.Lists.newArrayList; +import static org.fest.assertions.Assertions.assertThat; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class CheckAlertThresholdsTest { @@ -70,7 +68,7 @@ public class CheckAlertThresholdsTest { context = mock(DecoratorContext.class); periods = mock(Periods.class); i18n = mock(I18n.class); - when(i18n.message(Mockito.any(Locale.class), Mockito.eq("variation"), Mockito.isNull(String.class))).thenReturn("variation"); + when(i18n.message(Mockito.any(Locale.class), Mockito.eq("variation"), Mockito.eq("variation"))).thenReturn("variation"); measureClasses = new Measure(CoreMetrics.CLASSES, 20d); measureCoverage = new Measure(CoreMetrics.COVERAGE, 35d); @@ -88,9 +86,25 @@ public class CheckAlertThresholdsTest { } @Test + public void should_generates_alert_status(){ + assertThat(decorator.generatesAlertStatus()).isEqualTo(CoreMetrics.ALERT_STATUS); + } + + @Test + public void should_depends_on_variations(){ + assertThat(decorator.dependsOnVariations()).isEqualTo(DecoratorBarriers.END_OF_TIME_MACHINE); + } + + @Test + public void should_depends_upon_metrics(){ + when(profile.getAlerts()).thenReturn(newArrayList(new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"))); + assertThat(decorator.dependsUponMetrics()).containsOnly(CoreMetrics.CLASSES); + } + + @Test public void shouldNotCreateAlertsWhenNoThresholds() { when(profile.getAlerts()).thenReturn(new ArrayList<Alert>()); - assertFalse(decorator.shouldExecuteOnProject(new Project("key"))); + assertThat(decorator.shouldExecuteOnProject(new Project("key"))).isFalse(); } @Test @@ -110,8 +124,8 @@ public class CheckAlertThresholdsTest { public void checkRootProjectsOnly() { when(project.getQualifier()).thenReturn(Resource.QUALIFIER_FILE); when(profile.getAlerts()).thenReturn(Arrays.asList( - new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"), - new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_GREATER, null, "35.0"))); + new Alert(null, CoreMetrics.CLASSES, Alert.OPERATOR_GREATER, null, "20"), + new Alert(null, CoreMetrics.COVERAGE, Alert.OPERATOR_GREATER, null, "35.0"))); decorator.decorate(project, context); |