aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java
index 746c47f3a58..46729866736 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateProviderTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.batch.qualitygate;
+import com.google.common.collect.ImmutableList;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -26,14 +27,17 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.slf4j.Logger;
import org.sonar.api.config.Settings;
+import org.sonar.api.measures.MetricFinder;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.bootstrap.ServerClient;
import org.sonar.wsclient.SonarClient;
import org.sonar.wsclient.base.HttpException;
import org.sonar.wsclient.qualitygate.QualityGateClient;
+import org.sonar.wsclient.qualitygate.QualityGateCondition;
import org.sonar.wsclient.qualitygate.QualityGateDetails;
import java.net.HttpURLConnection;
+import java.util.Collection;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -50,6 +54,9 @@ public class QualityGateProviderTest {
private ServerClient client;
@Mock
+ private MetricFinder metricFinder;
+
+ @Mock
private QualityGateClient qualityGateClient;
@Mock
@@ -64,8 +71,8 @@ public class QualityGateProviderTest {
@Test
public void should_load_empty_quality_gate_from_default_settings() {
- assertThat(new QualityGateProvider().provide(settings, client).conditions()).isEmpty();
- assertThat(new QualityGateProvider().init(settings, client, logger).isEnabled()).isFalse();
+ assertThat(new QualityGateProvider().provide(settings, client, metricFinder).conditions()).isEmpty();
+ assertThat(new QualityGateProvider().init(settings, client, metricFinder, logger).isEnabled()).isFalse();
verify(logger).info("No quality gate is configured.");
}
@@ -76,7 +83,7 @@ public class QualityGateProviderTest {
QualityGateDetails qGate = mock(QualityGateDetails.class);
when(qualityGateClient.show(qGateName)).thenReturn(qGate);
when(qGate.name()).thenReturn(qGateName);
- QualityGate actualGate = new QualityGateProvider().init(settings, client, logger);
+ QualityGate actualGate = new QualityGateProvider().init(settings, client, metricFinder, logger);
assertThat(actualGate.name()).isEqualTo(qGateName);
assertThat(actualGate.isEnabled()).isTrue();
verify(logger).info("Loaded quality gate '{}'", qGateName);
@@ -90,8 +97,18 @@ public class QualityGateProviderTest {
QualityGateDetails qGate = mock(QualityGateDetails.class);
when(qualityGateClient.show(qGateId)).thenReturn(qGate);
when(qGate.name()).thenReturn(qGateName);
- assertThat(new QualityGateProvider().init(settings, client, logger).name()).isEqualTo(qGateName);
+ String metricKey1 = "metric1";
+ QualityGateCondition serverCondition1 = mock(QualityGateCondition.class);
+ when(serverCondition1.metricKey()).thenReturn(metricKey1);
+ String metricKey2 = "metric2";
+ QualityGateCondition serverCondition2 = mock(QualityGateCondition.class);
+ when(serverCondition2.metricKey()).thenReturn(metricKey2);
+ Collection<QualityGateCondition> conditions = ImmutableList.of(serverCondition1, serverCondition2);
+ when(qGate.conditions()).thenReturn(conditions);
+ assertThat(new QualityGateProvider().init(settings, client, metricFinder, logger).name()).isEqualTo(qGateName);
verify(logger).info("Loaded quality gate '{}'", qGateName);
+ verify(metricFinder).findByKey(metricKey1);
+ verify(metricFinder).findByKey(metricKey2);
}
@Test(expected = MessageException.class)
@@ -99,7 +116,7 @@ public class QualityGateProviderTest {
String qGateName = "Sonar way";
when(settings.getString("sonar.qualitygate")).thenReturn(qGateName);
when(qualityGateClient.show(qGateName)).thenThrow(new HttpException("http://server/api/qualitygates/show?name=Sonar%20way", HttpURLConnection.HTTP_NOT_FOUND));
- new QualityGateProvider().provide(settings, client);
+ new QualityGateProvider().provide(settings, client, metricFinder);
}
@Test(expected = HttpException.class)
@@ -107,7 +124,7 @@ public class QualityGateProviderTest {
String qGateName = "Sonar way";
when(settings.getString("sonar.qualitygate")).thenReturn(qGateName);
when(qualityGateClient.show(qGateName)).thenThrow(new HttpException("http://server/api/qualitygates/show?name=Sonar%20way", HttpURLConnection.HTTP_NOT_ACCEPTABLE));
- new QualityGateProvider().provide(settings, client);
+ new QualityGateProvider().provide(settings, client, metricFinder);
}
}