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;
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);
}
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;
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 {
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);
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
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);
import org.sonar.api.BatchComponent;
import org.sonar.api.ServerComponent;
-import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import java.util.Locale;
/**
* 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.
* @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);
}