aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-auth-common/src
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 /server/sonar-auth-common/src
parent92f482f2aa43e4aa36e0fda377d13b9dc3282ff9 (diff)
downloadsonarqube-a3d88ea27c35921647d7602755828ca73e15e865.tar.gz
sonarqube-a3d88ea27c35921647d7602755828ca73e15e865.zip
SONAR-15631 - Refactor UTs to stop using ExpectedException
Diffstat (limited to 'server/sonar-auth-common/src')
-rw-r--r--server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java20
1 files changed, 7 insertions, 13 deletions
diff --git a/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java b/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java
index 02730651fc5..6488c491d90 100644
--- a/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java
+++ b/server/sonar-auth-common/src/test/java/org/sonar/auth/OAuthRestClientTest.java
@@ -32,20 +32,16 @@ import okhttp3.mockwebserver.MockWebServer;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import static java.lang.String.format;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.sonar.auth.OAuthRestClient.executePaginatedRequest;
import static org.sonar.auth.OAuthRestClient.executeRequest;
public class OAuthRestClientTest {
-
- @Rule
- public ExpectedException expectedException = ExpectedException.none();
-
@Rule
public MockWebServer mockWebServer = new MockWebServer();
@@ -77,10 +73,9 @@ public class OAuthRestClientTest {
public void fail_to_execute_request() throws IOException {
mockWebServer.enqueue(new MockResponse().setResponseCode(404).setBody("Error!"));
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(format("Fail to execute request '%s/test'. HTTP code: 404, response: Error!", serverUrl));
-
- executeRequest(serverUrl + "/test", oAuth20Service, auth2AccessToken);
+ assertThatThrownBy(() -> executeRequest(serverUrl + "/test", oAuth20Service, auth2AccessToken))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(format("Fail to execute request '%s/test'. HTTP code: 404, response: Error!", serverUrl));
}
@Test
@@ -135,10 +130,9 @@ public class OAuthRestClientTest {
.setBody("A"));
mockWebServer.enqueue(new MockResponse().setResponseCode(404).setBody("Error!"));
- expectedException.expect(IllegalStateException.class);
- expectedException.expectMessage(format("Fail to execute request '%s/test?per_page=100&page=2'. HTTP code: 404, response: Error!", serverUrl));
-
- executePaginatedRequest(serverUrl + "/test", oAuth20Service, auth2AccessToken, Arrays::asList);
+ assertThatThrownBy(() -> executePaginatedRequest(serverUrl + "/test", oAuth20Service, auth2AccessToken, Arrays::asList))
+ .isInstanceOf(IllegalStateException.class)
+ .hasMessage(format("Fail to execute request '%s/test?per_page=100&page=2'. HTTP code: 404, response: Error!", serverUrl));
}
private class TestAPI extends DefaultApi20 {