aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate
diff options
context:
space:
mode:
authorKlaudio Sinani <klaudio.sinani@sonarsource.com>2021-11-17 22:54:06 +0100
committersonartech <sonartech@sonarsource.com>2021-11-19 20:03:27 +0000
commita3d88ea27c35921647d7602755828ca73e15e865 (patch)
tree5626c38afab1ea00ab9897da431476c17b478bbe /sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate
parent92f482f2aa43e4aa36e0fda377d13b9dc3282ff9 (diff)
downloadsonarqube-a3d88ea27c35921647d7602755828ca73e15e865.tar.gz
sonarqube-a3d88ea27c35921647d7602755828ca73e15e865.zip
SONAR-15631 - Refactor UTs to stop using ExpectedException
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java65
1 files changed, 30 insertions, 35 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java
index 587b9d10b21..7f73a26aab8 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java
@@ -25,7 +25,6 @@ import com.tngtech.java.junit.dataprovider.UseDataProvider;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.ArgumentMatcher;
import org.mockito.Mockito;
@@ -44,6 +43,7 @@ import org.sonarqube.ws.client.MockWsResponse;
import org.sonarqube.ws.client.WsRequest;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
@@ -60,9 +60,6 @@ public class QualityGateCheckTest {
@Rule
public LogTester logTester = new LogTester();
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
QualityGateCheck underTest = new QualityGateCheck(wsClient, analysisMode, reportMetadataHolder, properties);
@Before
@@ -127,9 +124,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
}
@Test
@@ -145,9 +142,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
}
@Test
@@ -164,10 +161,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
-
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com");
}
@Test
@@ -180,9 +176,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("Quality Gate check timeout exceeded - View details on http://dashboard-url.com");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessage("Quality Gate check timeout exceeded - View details on http://dashboard-url.com");
}
@Test
@@ -197,9 +193,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("Failed to get Quality Gate status - HTTP code 400: content");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessage("Failed to get Quality Gate status - HTTP code 400: content");
}
@Test
@@ -217,9 +213,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Failed to parse response from quality-gate-url");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("Failed to parse response from quality-gate-url");
}
@Test
@@ -231,9 +227,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("Failed to get CE Task status - HTTP code 400: content");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessage("Failed to get CE Task status - HTTP code 400: content");
}
@Test
@@ -249,9 +245,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(IllegalStateException.class);
- exception.expectMessage("Failed to parse response from ce-task-url");
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage("Failed to parse response from ce-task-url");
}
@Test
@@ -265,9 +261,9 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(MessageException.class);
- exception.expectMessage("CE Task finished abnormally with status: " + taskStatus.name());
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(MessageException.class)
+ .hasMessageContaining("CE Task finished abnormally with status: " + taskStatus.name());
}
private WsRequest newGetCeTaskRequest() {
@@ -302,9 +298,8 @@ public class QualityGateCheckTest {
underTest.start();
- exception.expect(IllegalStateException.class);
-
- underTest.await();
+ assertThatThrownBy(() -> underTest.await())
+ .isInstanceOf(IllegalStateException.class);
}
private WsRequest newGetQualityGateRequest() {