From a3d88ea27c35921647d7602755828ca73e15e865 Mon Sep 17 00:00:00 2001 From: Klaudio Sinani Date: Wed, 17 Nov 2021 22:54:06 +0100 Subject: SONAR-15631 - Refactor UTs to stop using ExpectedException --- .../java/org/sonar/auth/OAuthRestClientTest.java | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'server/sonar-auth-common/src') 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 { -- cgit v1.2.3