diff options
3 files changed, 27 insertions, 19 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); diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/i18n/I18n.java b/sonar-plugin-api/src/main/java/org/sonar/api/i18n/I18n.java index 2588ea5d58f..0a8b8543805 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/i18n/I18n.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/i18n/I18n.java @@ -22,7 +22,6 @@ package org.sonar.api.i18n; import org.sonar.api.BatchComponent; import org.sonar.api.ServerComponent; -import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.util.Locale; @@ -37,7 +36,7 @@ public interface I18n extends ServerComponent, BatchComponent { /** * Searches the message of the <code>key</code> for the <code>locale</code> in the list of available bundles. * <br> - * If not found in any bundle, <code>defaultText</code> is returned. + * If not found in any bundle, <code>defaultValue</code> is returned. * <p/> * If additional parameters are given (in the objects list), the result is used as a message pattern * to use in a MessageFormat object along with the given parameters. @@ -48,7 +47,6 @@ public interface I18n extends ServerComponent, BatchComponent { * @param parameters the parameters used to format the message from the translated pattern. * @return the message formatted with the translated pattern and the given parameters */ - @CheckForNull String message(final Locale locale, final String key, @Nullable final String defaultValue, final Object... parameters); } |