]> source.dussan.org Git - sonarqube.git/commitdiff
Fix quality flaws
authorJulien Lancelot <julien.lancelot@gmail.com>
Thu, 11 Jul 2013 17:08:26 +0000 (19:08 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Thu, 11 Jul 2013 17:08:26 +0000 (19:08 +0200)
plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/sensors/CheckAlertThresholds.java
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/sensors/CheckAlertThresholdsTest.java
sonar-plugin-api/src/main/java/org/sonar/api/i18n/I18n.java

index b03d894c863264c3ae55636d37094c5a6d7718ae..197dfb3fd41d659fe4c7c782008048e3a50b488b 100644 (file)
@@ -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);
     }
 
index b6d2942d146555217ac2ced80e3dcfbb02e31a7e..9a48abfd4c9b8582dcaf9fbea25d1757b01ec438 100644 (file)
@@ -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);
@@ -87,10 +85,26 @@ public class CheckAlertThresholdsTest {
     when(project.getQualifier()).thenReturn(Qualifiers.PROJECT);
   }
 
+  @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);
 
index 2588ea5d58f51a31b716d0ab2fafa6afab73e937..0a8b8543805a8791aaef9da102e58110239191d7 100644 (file)
@@ -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);
 
 }