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 --- .../org/sonar/auth/github/GitHubIdentityProviderTest.java | 11 ++++------- .../org/sonar/auth/github/UserIdentityFactoryImplTest.java | 4 ---- 2 files changed, 4 insertions(+), 11 deletions(-) (limited to 'server/sonar-auth-github/src') diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubIdentityProviderTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubIdentityProviderTest.java index d7ee6b2efd2..2e5e47a770f 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubIdentityProviderTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/GitHubIdentityProviderTest.java @@ -19,21 +19,18 @@ */ package org.sonar.auth.github; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.server.authentication.OAuth2IdentityProvider; 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.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class GitHubIdentityProviderTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); private MapSettings settings = new MapSettings(); private GitHubSettings gitHubSettings = new GitHubSettings(settings.asConfig()); @@ -128,9 +125,9 @@ public class GitHubIdentityProviderTest { setSettings(false); OAuth2IdentityProvider.InitContext context = mock(OAuth2IdentityProvider.InitContext.class); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("GitHub authentication is disabled"); - underTest.init(context); + assertThatThrownBy(() -> underTest.init(context)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("GitHub authentication is disabled"); } @Test diff --git a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/UserIdentityFactoryImplTest.java b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/UserIdentityFactoryImplTest.java index 4755660dd41..09f03dbc5b0 100644 --- a/server/sonar-auth-github/src/test/java/org/sonar/auth/github/UserIdentityFactoryImplTest.java +++ b/server/sonar-auth-github/src/test/java/org/sonar/auth/github/UserIdentityFactoryImplTest.java @@ -19,9 +19,7 @@ */ package org.sonar.auth.github; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.server.authentication.UserIdentity; @@ -31,8 +29,6 @@ import static org.assertj.core.api.Assertions.assertThat; public class UserIdentityFactoryImplTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); private MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, GitHubSettings.definitions())); private UserIdentityFactoryImpl underTest = new UserIdentityFactoryImpl(); -- cgit v1.2.3