@@ -25,7 +25,6 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
@@ -42,9 +41,6 @@ public class ItCoverageSensorTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
@Before |
@@ -25,7 +25,6 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
@@ -42,9 +41,6 @@ public class OverallCoverageSensorTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
@Before |
@@ -25,7 +25,6 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
@@ -42,9 +41,6 @@ public class UtCoverageSensorTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
@Before |
@@ -25,7 +25,6 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
@@ -43,9 +42,6 @@ public class CpdTokenizerSensorTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
@Before |
@@ -26,17 +26,17 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.measure.MetricFinder; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
import org.sonar.api.batch.measure.MetricFinder; | |||
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; | |||
import org.sonar.api.batch.sensor.internal.SensorContextTester; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.measures.Metric; | |||
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.when; | |||
@@ -48,9 +48,6 @@ public class MeasureSensorTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
private MetricFinder metricFinder; | |||
@@ -124,8 +121,7 @@ public class MeasureSensorTest { | |||
InputFile inputFile = new TestInputFileBuilder("foo", "src/foo.xoo").setLanguage("xoo").setModuleBaseDir(baseDir.toPath()).build(); | |||
context.fileSystem().add(inputFile); | |||
thrown.expect(IllegalStateException.class); | |||
sensor.execute(context); | |||
assertThatThrownBy(() -> sensor.execute(context)) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
} |
@@ -25,7 +25,6 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.fs.InputFile; | |||
import org.sonar.api.batch.fs.TextRange; | |||
@@ -44,9 +43,6 @@ public class SignificantCodeSensorTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
private InputFile inputFile; |
@@ -26,9 +26,9 @@ import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.sensor.highlighting.TypeOfText; | |||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
import org.sonar.api.batch.sensor.highlighting.TypeOfText; | |||
import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; | |||
import org.sonar.api.batch.sensor.internal.SensorContextTester; | |||
@@ -19,9 +19,7 @@ | |||
*/ | |||
package org.sonar.xoo.rule; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition; | |||
import org.sonar.api.server.profile.BuiltInQualityProfilesDefinition.BuiltInQualityProfile; | |||
@@ -30,9 +28,6 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
public class XooBuiltInQualityProfilesDefinitionTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private XooBuiltInQualityProfilesDefinition underTest = new XooBuiltInQualityProfilesDefinition(); | |||
@Test |
@@ -26,14 +26,13 @@ import org.apache.commons.io.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.scm.BlameCommand.BlameInput; | |||
import org.sonar.api.batch.scm.BlameCommand.BlameOutput; | |||
import org.sonar.api.batch.scm.BlameLine; | |||
import org.sonar.api.batch.fs.internal.DefaultFileSystem; | |||
import org.sonar.api.batch.fs.internal.DefaultInputFile; | |||
import org.sonar.api.batch.fs.internal.TestInputFileBuilder; | |||
import org.sonar.api.batch.scm.BlameCommand.BlameInput; | |||
import org.sonar.api.batch.scm.BlameCommand.BlameOutput; | |||
import org.sonar.api.batch.scm.BlameLine; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.xoo.Xoo; | |||
@@ -47,9 +46,6 @@ public class XooBlameCommandTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private DefaultFileSystem fs; | |||
private File baseDir; | |||
private BlameInput input; |
@@ -24,7 +24,6 @@ import java.io.IOException; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -35,9 +34,6 @@ public class XooIgnoreCommandTest { | |||
@Rule | |||
public TemporaryFolder temp = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private File baseDir; | |||
@Before |
@@ -19,10 +19,10 @@ | |||
*/ | |||
package org.sonar.alm.client.bitbucketserver; | |||
import java.util.Optional; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.*; | |||
import java.util.Optional; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
public class BranchesListTest { | |||
@@ -22,24 +22,19 @@ package org.sonar.alm.client.github.config; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Random; | |||
import java.util.stream.Stream; | |||
import javax.annotation.Nullable; | |||
import org.apache.commons.lang.ArrayUtils; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class GithubAppConfigurationTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
@UseDataProvider("incompleteConfigurationParametersSonarQube") | |||
@@ -54,9 +49,9 @@ public class GithubAppConfigurationTest { | |||
public void getId_throws_ISE_if_config_is_incomplete(@Nullable Long applicationId, @Nullable String privateKey, @Nullable String apiEndpoint) { | |||
GithubAppConfiguration underTest = new GithubAppConfiguration(applicationId, privateKey, apiEndpoint); | |||
expectConfigurationIncompleteISE(); | |||
underTest.getId(); | |||
assertThatThrownBy(underTest::getId) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessageContaining("Configuration is not complete"); | |||
} | |||
@Test | |||
@@ -72,9 +67,9 @@ public class GithubAppConfigurationTest { | |||
public void getPrivateKeyFile_throws_ISE_if_config_is_incomplete(@Nullable Long applicationId, @Nullable String privateKey, @Nullable String apiEndpoint) { | |||
GithubAppConfiguration underTest = new GithubAppConfiguration(applicationId, privateKey, apiEndpoint); | |||
expectConfigurationIncompleteISE(); | |||
underTest.getPrivateKey(); | |||
assertThatThrownBy(underTest::getPrivateKey) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessageContaining("Configuration is not complete"); | |||
} | |||
@DataProvider | |||
@@ -144,11 +139,6 @@ public class GithubAppConfigurationTest { | |||
assertThat(underTest.hashCode()).isNotEqualTo(new GithubAppConfiguration(applicationId, privateKey, apiEndpoint)); | |||
} | |||
private void expectConfigurationIncompleteISE() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Configuration is not complete"); | |||
} | |||
private GithubAppConfiguration newValidConfiguration(long applicationId) { | |||
return new GithubAppConfiguration(applicationId, randomAlphabetic(6), randomAlphabetic(6)); | |||
} |
@@ -20,7 +20,6 @@ | |||
package org.sonar.alm.client.github.security; | |||
import org.junit.Test; | |||
import org.sonar.alm.client.github.security.AppToken; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
@@ -20,14 +20,12 @@ | |||
package org.sonar.alm.client.github.security; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import java.io.IOException; | |||
import java.security.spec.InvalidKeySpecException; | |||
import java.time.Clock; | |||
import java.time.Instant; | |||
import java.time.ZoneId; | |||
import java.util.Random; | |||
import org.junit.Test; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.alm.client.github.config.GithubAppConfiguration; |
@@ -19,21 +19,18 @@ | |||
*/ | |||
package org.sonar.auth.bitbucket; | |||
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 BitbucketIdentityProviderTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private final MapSettings settings = new MapSettings(); | |||
private final BitbucketSettings bitbucketSettings = new BitbucketSettings(settings.asConfig()); | |||
@@ -75,9 +72,9 @@ public class BitbucketIdentityProviderTest { | |||
enableBitbucketAuthentication(false); | |||
OAuth2IdentityProvider.InitContext context = mock(OAuth2IdentityProvider.InitContext.class); | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Bitbucket authentication is disabled"); | |||
underTest.init(context); | |||
assertThatThrownBy(() -> underTest.init(context)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Bitbucket authentication is disabled"); | |||
} | |||
private void enableBitbucketAuthentication(boolean enabled) { |
@@ -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 { |
@@ -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 |
@@ -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(); |
@@ -20,9 +20,7 @@ | |||
package org.sonar.auth.gitlab; | |||
import org.assertj.core.api.Assertions; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.server.authentication.Display; | |||
import org.sonar.api.server.authentication.OAuth2IdentityProvider; | |||
@@ -20,9 +20,7 @@ | |||
package org.sonar.auth.gitlab; | |||
import org.junit.Before; | |||
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.utils.System2; | |||
@@ -37,8 +35,6 @@ import static org.sonar.auth.gitlab.GitLabSettings.GITLAB_AUTH_URL; | |||
public class GitLabSettingsTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private MapSettings settings; | |||
private GitLabSettings config; |
@@ -26,6 +26,7 @@ import javax.security.auth.callback.UnsupportedCallbackException; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.mock; | |||
public class CallbackHandlerImplTest { | |||
@@ -40,9 +41,12 @@ public class CallbackHandlerImplTest { | |||
assertThat(passwordCallback.getPassword()).isEqualTo("secret".toCharArray()); | |||
} | |||
@Test(expected = UnsupportedCallbackException.class) | |||
public void unsupportedCallback() throws Exception { | |||
new CallbackHandlerImpl("tester", "secret").handle(new Callback[] {mock(Callback.class)}); | |||
@Test | |||
public void unsupportedCallback() { | |||
assertThatThrownBy(() -> { | |||
new CallbackHandlerImpl("tester", "secret").handle(new Callback[] {mock(Callback.class)}); | |||
}) | |||
.isInstanceOf(UnsupportedCallbackException.class); | |||
} | |||
} |
@@ -23,6 +23,7 @@ import javax.naming.Context; | |||
import javax.naming.NamingException; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.doThrow; | |||
import static org.mockito.Mockito.mock; | |||
@@ -36,11 +37,12 @@ public class ContextHelperTest { | |||
ContextHelper.closeQuietly(context); | |||
} | |||
@Test(expected = NamingException.class) | |||
@Test | |||
public void shouldNotSwallow() throws Exception { | |||
Context context = mock(Context.class); | |||
doThrow(new NamingException()).when(context).close(); | |||
ContextHelper.close(context, false); | |||
assertThatThrownBy(() -> ContextHelper.close(context, false)) | |||
.isInstanceOf(NamingException.class); | |||
} | |||
@Test |
@@ -26,21 +26,16 @@ import javax.naming.NamingException; | |||
import javax.naming.directory.SearchControls; | |||
import org.junit.BeforeClass; | |||
import org.junit.ClassRule; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.auth.ldap.server.LdapServer; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class LdapSearchTest { | |||
@ClassRule | |||
public static LdapServer server = new LdapServer("/users.example.org.ldif"); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private static Map<String, LdapContextFactory> contextFactories; | |||
@BeforeClass | |||
@@ -63,9 +58,10 @@ public class LdapSearchTest { | |||
assertThat(search.getReturningAttributes()).isEqualTo(new String[] {"objectClass"}); | |||
assertThat(search.toString()).isEqualTo("LdapSearch{baseDn=dc=example,dc=org, scope=subtree, request=(objectClass={0}), parameters=[inetOrgPerson], attributes=[objectClass]}"); | |||
assertThat(enumerationToArrayList(search.find()).size()).isEqualTo(3); | |||
thrown.expect(NamingException.class); | |||
thrown.expectMessage("Non unique result for " + search.toString()); | |||
search.findUnique(); | |||
assertThatThrownBy(() -> search.findUnique()) | |||
.isInstanceOf(NamingException.class) | |||
.hasMessage("Non unique result for " + search.toString()); | |||
} | |||
@Test |
@@ -21,30 +21,25 @@ package org.sonar.auth.ldap; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.config.internal.MapSettings; | |||
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.when; | |||
import static org.sonar.auth.ldap.LdapAutodiscovery.LdapSrvRecord; | |||
public class LdapSettingsManagerTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void shouldFailWhenNoLdapUrl() { | |||
MapSettings settings = generateMultipleLdapSettingsWithUserAndGroupMapping(); | |||
settings.removeProperty("ldap.example.url"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
thrown.expect(LdapException.class); | |||
thrown.expectMessage("The property 'ldap.example.url' property is empty while it is mandatory."); | |||
settingsManager.getContextFactories(); | |||
assertThatThrownBy(settingsManager::getContextFactories) | |||
.isInstanceOf(LdapException.class) | |||
.hasMessage("The property 'ldap.example.url' property is empty while it is mandatory."); | |||
} | |||
@Test | |||
@@ -53,11 +48,9 @@ public class LdapSettingsManagerTest { | |||
settings.setProperty("ldap.url", "ldap://foo"); | |||
LdapSettingsManager settingsManager = new LdapSettingsManager(settings.asConfig(), new LdapAutodiscovery()); | |||
thrown.expect(LdapException.class); | |||
thrown | |||
.expectMessage( | |||
"When defining multiple LDAP servers with the property 'ldap.servers', all LDAP properties must be linked to one of those servers. Please remove properties like 'ldap.url', 'ldap.realm', ..."); | |||
settingsManager.getContextFactories(); | |||
assertThatThrownBy(settingsManager::getContextFactories) | |||
.isInstanceOf(LdapException.class) | |||
.hasMessage("When defining multiple LDAP servers with the property 'ldap.servers', all LDAP properties must be linked to one of those servers. Please remove properties like 'ldap.url', 'ldap.realm', ..."); | |||
} | |||
@Test | |||
@@ -98,10 +91,9 @@ public class LdapSettingsManagerTest { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
generateAutodiscoverSettings().asConfig(), ldapAutodiscovery); | |||
thrown.expect(LdapException.class); | |||
thrown.expectMessage("The property 'ldap.url' is empty and SonarQube is not able to auto-discover any LDAP server."); | |||
settingsManager.getContextFactories(); | |||
assertThatThrownBy(settingsManager::getContextFactories) | |||
.isInstanceOf(LdapException.class) | |||
.hasMessage("The property 'ldap.url' is empty and SonarQube is not able to auto-discover any LDAP server."); | |||
} | |||
/** | |||
@@ -139,9 +131,9 @@ public class LdapSettingsManagerTest { | |||
LdapSettingsManager settingsManager = new LdapSettingsManager( | |||
new MapSettings().asConfig(), new LdapAutodiscovery()); | |||
thrown.expect(LdapException.class); | |||
thrown.expectMessage("The property 'ldap.url' is empty and no realm configured to try auto-discovery."); | |||
settingsManager.getContextFactories(); | |||
assertThatThrownBy(settingsManager::getContextFactories) | |||
.isInstanceOf(LdapException.class) | |||
.hasMessage("The property 'ldap.url' is empty and no realm configured to try auto-discovery."); | |||
} | |||
private MapSettings generateMultipleLdapSettingsWithUserAndGroupMapping() { |
@@ -22,21 +22,18 @@ package org.sonar.auth.saml; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.config.PropertyDefinitions; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.utils.System2; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class SamlSettingsTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private MapSettings settings = new MapSettings(new PropertyDefinitions(System2.INSTANCE, SamlSettings.definitions())); | |||
@@ -177,42 +174,37 @@ public class SamlSettingsTest { | |||
@Test | |||
public void fail_to_get_provider_id_when_null() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Provider ID is missing"); | |||
underTest.getProviderId(); | |||
assertThatThrownBy(() -> underTest.getProviderId()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Provider ID is missing"); | |||
} | |||
@Test | |||
public void fail_to_get_login_url_when_null() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Login URL is missing"); | |||
underTest.getLoginUrl(); | |||
assertThatThrownBy(() -> underTest.getLoginUrl()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Login URL is missing"); | |||
} | |||
@Test | |||
public void fail_to_get_certificate_when_null() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Certificate is missing"); | |||
underTest.getCertificate(); | |||
assertThatThrownBy(() -> underTest.getCertificate()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Certificate is missing"); | |||
} | |||
@Test | |||
public void fail_to_get_user_login_attribute_when_null() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("User login attribute is missing"); | |||
underTest.getUserLogin(); | |||
assertThatThrownBy(() -> underTest.getUserLogin()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("User login attribute is missing"); | |||
} | |||
@Test | |||
public void fail_to_get_user_name_attribute_when_null() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("User name attribute is missing"); | |||
underTest.getUserName(); | |||
assertThatThrownBy(() -> underTest.getUserName()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("User name attribute is missing"); | |||
} | |||
private void initAllSettings() { |
@@ -27,7 +27,6 @@ import java.util.stream.IntStream; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.queue.CeTaskSubmit.Component; | |||
@@ -50,9 +49,9 @@ import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptyMap; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.assertj.core.api.Assertions.catchThrowable; | |||
import static org.assertj.core.api.Assertions.tuple; | |||
import static org.hamcrest.Matchers.startsWith; | |||
import static org.sonar.ce.queue.CeQueue.SubmitOption.UNIQUE_QUEUE_PER_MAIN_COMPONENT; | |||
public class CeQueueImplTest { | |||
@@ -62,8 +61,6 @@ public class CeQueueImplTest { | |||
private System2 system2 = new TestSystem2().setNow(NOW); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public DbTester db = DbTester.create(system2); | |||
@@ -395,10 +392,9 @@ public class CeQueueImplTest { | |||
submit(CeTaskTypes.REPORT, newComponent(randomAlphabetic(11))); | |||
CeQueueDto ceQueueDto = db.getDbClient().ceQueueDao().peek(session, WORKER_UUID, false, false).get(); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage(startsWith("Task is in progress and can't be canceled")); | |||
underTest.cancel(db.getSession(), ceQueueDto); | |||
assertThatThrownBy(() -> underTest.cancel(db.getSession(), ceQueueDto)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessageStartingWith("Task is in progress and can't be canceled"); | |||
} | |||
@Test |
@@ -19,16 +19,13 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.analysis; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class AnalysisImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private static final long ID = 10; | |||
private static final String UUID = "uuid "; | |||
@@ -47,22 +44,16 @@ public class AnalysisImplTest { | |||
@Test | |||
public void fail_with_NPE_when_building_snapshot_without_uuid() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("uuid cannot be null"); | |||
new Analysis.Builder() | |||
.setCreatedAt(CREATED_AT) | |||
.build(); | |||
assertThatThrownBy(() -> new Analysis.Builder().setCreatedAt(CREATED_AT).build()) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("uuid cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_building_snapshot_without_created_at() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("createdAt cannot be null"); | |||
new Analysis.Builder() | |||
.setUuid(UUID) | |||
.build(); | |||
assertThatThrownBy(() -> new Analysis.Builder().setUuid(UUID).build()) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("createdAt cannot be null"); | |||
} | |||
@Test |
@@ -26,9 +26,7 @@ import java.util.Arrays; | |||
import java.util.Optional; | |||
import java.util.stream.Stream; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.component.DefaultBranchImpl; | |||
import org.sonar.core.platform.PlatformEditionProvider; | |||
@@ -36,6 +34,7 @@ import org.sonar.db.component.BranchType; | |||
import org.sonar.server.project.Project; | |||
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.when; | |||
import static org.sonar.core.platform.EditionProvider.Edition; | |||
@@ -50,28 +49,24 @@ public class AnalysisMetadataHolderImplTest { | |||
.build(); | |||
private static final long SOME_DATE = 10000000L; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private final PlatformEditionProvider editionProvider = mock(PlatformEditionProvider.class); | |||
private final AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
@Test | |||
public void setUuid_throws_NPE_is_parameter_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("Analysis uuid can't be null"); | |||
underTest.setUuid(null); | |||
assertThatThrownBy(() -> underTest.setUuid(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Analysis uuid can't be null"); | |||
} | |||
@Test | |||
public void setUuid_throws_ISE_if_called_twice() { | |||
underTest.setUuid("org1"); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Analysis uuid has already been set"); | |||
underTest.setUuid("org1"); | |||
assertThatThrownBy(() -> underTest.setUuid("org1")) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Analysis uuid has already been set"); | |||
} | |||
@Test | |||
@@ -84,10 +79,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void getAnalysisDate_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Analysis date has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getAnalysisDate(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getAnalysisDate()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Analysis date has not been set"); | |||
} | |||
@Test | |||
@@ -95,10 +89,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setAnalysisDate(SOME_DATE); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Analysis date has already been set"); | |||
underTest.setAnalysisDate(SOME_DATE); | |||
assertThatThrownBy(() -> underTest.setAnalysisDate(SOME_DATE)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Analysis date has already been set"); | |||
} | |||
@Test | |||
@@ -111,10 +104,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void getForkDate_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Fork date has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getForkDate(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getForkDate()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Fork date has not been set"); | |||
} | |||
@Test | |||
@@ -122,10 +114,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setForkDate(SOME_DATE); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Fork date has already been set"); | |||
underTest.setForkDate(SOME_DATE); | |||
assertThatThrownBy(() -> underTest.setForkDate(SOME_DATE)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Fork date has already been set"); | |||
} | |||
@Test | |||
@@ -158,18 +149,16 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void isFirstAnalysis_throws_ISE_when_base_project_snapshot_is_not_set() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Base project snapshot has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).isFirstAnalysis(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).isFirstAnalysis()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Base project snapshot has not been set"); | |||
} | |||
@Test | |||
public void baseProjectSnapshot_throws_ISE_when_base_project_snapshot_is_not_set() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Base project snapshot has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getBaseAnalysis(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getBaseAnalysis()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Base project snapshot has not been set"); | |||
} | |||
@Test | |||
@@ -177,9 +166,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setBaseAnalysis(baseProjectAnalysis); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Base project snapshot has already been set"); | |||
underTest.setBaseAnalysis(baseProjectAnalysis); | |||
assertThatThrownBy(() -> underTest.setBaseAnalysis(baseProjectAnalysis)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Base project snapshot has already been set"); | |||
} | |||
@Test | |||
@@ -202,10 +191,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void isCrossProjectDuplicationEnabled_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Cross project duplication flag has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).isCrossProjectDuplicationEnabled(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).isCrossProjectDuplicationEnabled()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Cross project duplication flag has not been set"); | |||
} | |||
@Test | |||
@@ -213,9 +201,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setCrossProjectDuplicationEnabled(true); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Cross project duplication flag has already been set"); | |||
underTest.setCrossProjectDuplicationEnabled(false); | |||
assertThatThrownBy(() -> underTest.setCrossProjectDuplicationEnabled(false)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Cross project duplication flag has already been set"); | |||
} | |||
@Test | |||
@@ -229,10 +217,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void getBranch_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Branch has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getBranch(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getBranch()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Branch has not been set"); | |||
} | |||
@Test | |||
@@ -240,9 +227,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setBranch(new DefaultBranchImpl()); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Branch has already been set"); | |||
underTest.setBranch(new DefaultBranchImpl()); | |||
assertThatThrownBy(() -> underTest.setBranch(new DefaultBranchImpl())) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Branch has already been set"); | |||
} | |||
@Test | |||
@@ -278,10 +265,9 @@ public class AnalysisMetadataHolderImplTest { | |||
when(branch.isMain()).thenReturn(false); | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Branches and Pull Requests are not supported in Community Edition"); | |||
underTest.setBranch(branch); | |||
assertThatThrownBy(() -> underTest.setBranch(branch)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Branches and Pull Requests are not supported in Community Edition"); | |||
} | |||
@DataProvider | |||
@@ -314,10 +300,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void getPullRequestId_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Pull request key has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getPullRequestKey(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getPullRequestKey()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Pull request key has not been set"); | |||
} | |||
@Test | |||
@@ -325,9 +310,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setPullRequestKey("pr-123"); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Pull request key has already been set"); | |||
underTest.setPullRequestKey("pr-234"); | |||
assertThatThrownBy(() -> underTest.setPullRequestKey("pr-234")) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Pull request key has already been set"); | |||
} | |||
@Test | |||
@@ -342,10 +327,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void getProject_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Project has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getProject(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getProject()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Project has not been set"); | |||
} | |||
@Test | |||
@@ -353,10 +337,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setProject(Project.from(newPrivateProjectDto())); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Project has already been set"); | |||
underTest.setProject(Project.from(newPrivateProjectDto())); | |||
assertThatThrownBy(() -> underTest.setProject(Project.from(newPrivateProjectDto()))) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Project has already been set"); | |||
} | |||
@Test | |||
@@ -370,10 +353,9 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void getRootComponentRef_throws_ISE_when_holder_is_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Root component ref has not been set"); | |||
new AnalysisMetadataHolderImpl(editionProvider).getRootComponentRef(); | |||
assertThatThrownBy(() -> new AnalysisMetadataHolderImpl(editionProvider).getRootComponentRef()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Root component ref has not been set"); | |||
} | |||
@Test | |||
@@ -381,9 +363,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setRootComponentRef(10); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Root component ref has already been set"); | |||
underTest.setRootComponentRef(9); | |||
assertThatThrownBy(() -> underTest.setRootComponentRef(9)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Root component ref has already been set"); | |||
} | |||
@Test | |||
@@ -402,9 +384,9 @@ public class AnalysisMetadataHolderImplTest { | |||
AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider); | |||
underTest.setScmRevision("bd56dab"); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("ScmRevision has already been set"); | |||
underTest.setScmRevision("bd56dab"); | |||
assertThatThrownBy(() -> underTest.setScmRevision("bd56dab")) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("ScmRevision has already been set"); | |||
} | |||
@Test | |||
@@ -455,9 +437,8 @@ public class AnalysisMetadataHolderImplTest { | |||
@Test | |||
public void isBranch_throws_ISE_for_not_initialized_branch() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Branch has not been set"); | |||
underTest.isBranch(); | |||
assertThatThrownBy(underTest::isBranch) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Branch has not been set"); | |||
} | |||
} |
@@ -19,18 +19,14 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.api.measurecomputer; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.ce.measure.Component; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class ComponentImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void create_project() { | |||
ComponentImpl component = new ComponentImpl("Project", Component.Type.PROJECT, null); | |||
@@ -59,43 +55,40 @@ public class ComponentImplTest { | |||
@Test | |||
public void fail_with_ISE_when_calling_get_file_attributes_on_not_file() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Only component of type FILE have a FileAttributes object"); | |||
ComponentImpl component = new ComponentImpl("Project", Component.Type.PROJECT, null); | |||
component.getFileAttributes(); | |||
assertThatThrownBy(() -> { | |||
ComponentImpl component = new ComponentImpl("Project", Component.Type.PROJECT, null); | |||
component.getFileAttributes(); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Only component of type FILE have a FileAttributes object"); | |||
} | |||
@Test | |||
public void fail_with_IAE_when_trying_to_create_a_file_without_file_attributes() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("omponent of type FILE must have a FileAttributes object"); | |||
new ComponentImpl("File", Component.Type.FILE, null); | |||
assertThatThrownBy(() -> new ComponentImpl("File", Component.Type.FILE, null)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessageContaining("omponent of type FILE must have a FileAttributes object"); | |||
} | |||
@Test | |||
public void fail_with_IAE_when_trying_to_create_not_a_file_with_file_attributes() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only component of type FILE have a FileAttributes object"); | |||
new ComponentImpl("Project", Component.Type.PROJECT, new ComponentImpl.FileAttributesImpl(null, true)); | |||
assertThatThrownBy(() -> new ComponentImpl("Project", Component.Type.PROJECT, new ComponentImpl.FileAttributesImpl(null, true))) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only component of type FILE have a FileAttributes object"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_creating_component_without_key() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Key cannot be null"); | |||
new ComponentImpl(null, Component.Type.PROJECT, null); | |||
assertThatThrownBy(() -> new ComponentImpl(null, Component.Type.PROJECT, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Key cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_creating_component_without_type() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Type cannot be null"); | |||
new ComponentImpl("Project", null, null); | |||
assertThatThrownBy(() -> new ComponentImpl("Project", null, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Type cannot be null"); | |||
} | |||
@Test |
@@ -25,7 +25,6 @@ import java.util.List; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.ce.measure.Component; | |||
import org.sonar.api.ce.measure.MeasureComputer; | |||
import org.sonar.api.config.internal.MapSettings; | |||
@@ -43,6 +42,7 @@ import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; | |||
import org.sonar.core.issue.DefaultIssue; | |||
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.when; | |||
import static org.sonar.api.measures.CoreMetrics.COMMENT_LINES_KEY; | |||
@@ -52,8 +52,6 @@ import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilde | |||
public class MeasureComputerContextImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private static final String INT_METRIC_KEY = "int_metric_key"; | |||
private static final String DOUBLE_METRIC_KEY = "double_metric_key"; | |||
@@ -134,11 +132,12 @@ public class MeasureComputerContextImplTest { | |||
@Test | |||
public void fail_with_IAE_when_get_measure_is_called_on_metric_not_in_input_list() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only metrics in [another metric] can be used to load measures"); | |||
MeasureComputerContextImpl underTest = newContext(PROJECT_REF, "another metric", "debt"); | |||
underTest.getMeasure(NCLOC_KEY); | |||
assertThatThrownBy(() -> { | |||
MeasureComputerContextImpl underTest = newContext(PROJECT_REF, "another metric", "debt"); | |||
underTest.getMeasure(NCLOC_KEY); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only metrics in [another metric] can be used to load measures"); | |||
} | |||
@Test | |||
@@ -171,11 +170,12 @@ public class MeasureComputerContextImplTest { | |||
@Test | |||
public void fail_with_IAE_when_get_children_measures_is_called_on_metric_not_in_input_list() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only metrics in [another metric] can be used to load measures"); | |||
MeasureComputerContextImpl underTest = newContext(PROJECT_REF, "another metric", "debt"); | |||
underTest.getChildrenMeasures(NCLOC_KEY); | |||
assertThatThrownBy(() -> { | |||
MeasureComputerContextImpl underTest = newContext(PROJECT_REF, "another metric", "debt"); | |||
underTest.getChildrenMeasures(NCLOC_KEY); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only metrics in [another metric] can be used to load measures"); | |||
} | |||
@Test | |||
@@ -230,22 +230,23 @@ public class MeasureComputerContextImplTest { | |||
@Test | |||
public void fail_with_IAE_when_add_measure_is_called_on_metric_not_in_output_list() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only metrics in [int_metric_key] can be used to add measures. Metric 'double_metric_key' is not allowed."); | |||
MeasureComputerContextImpl underTest = newContext(PROJECT_REF, NCLOC_KEY, INT_METRIC_KEY); | |||
underTest.addMeasure(DOUBLE_METRIC_KEY, 10); | |||
assertThatThrownBy(() -> { | |||
MeasureComputerContextImpl underTest = newContext(PROJECT_REF, NCLOC_KEY, INT_METRIC_KEY); | |||
underTest.addMeasure(DOUBLE_METRIC_KEY, 10); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only metrics in [int_metric_key] can be used to add measures. Metric 'double_metric_key' is not allowed."); | |||
} | |||
@Test | |||
public void fail_with_unsupported_operation_when_adding_measure_that_already_exists() { | |||
thrown.expect(UnsupportedOperationException.class); | |||
thrown.expectMessage("A measure on metric 'int_metric_key' already exists on component 'fileKey'"); | |||
measureRepository.addRawMeasure(FILE_1_REF, INT_METRIC_KEY, newMeasureBuilder().create(20)); | |||
MeasureComputerContextImpl underTest = newContext(FILE_1_REF, NCLOC_KEY, INT_METRIC_KEY); | |||
underTest.addMeasure(INT_METRIC_KEY, 10); | |||
assertThatThrownBy(() -> { | |||
measureRepository.addRawMeasure(FILE_1_REF, INT_METRIC_KEY, newMeasureBuilder().create(20)); | |||
MeasureComputerContextImpl underTest = newContext(FILE_1_REF, NCLOC_KEY, INT_METRIC_KEY); | |||
underTest.addMeasure(INT_METRIC_KEY, 10); | |||
}) | |||
.isInstanceOf(UnsupportedOperationException.class) | |||
.hasMessage("A measure on metric 'int_metric_key' already exists on component 'fileKey'"); | |||
} | |||
@Test |
@@ -19,17 +19,14 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.api.measurecomputer; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.ce.measure.MeasureComputer; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class MeasureComputerDefinitionImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void build_measure_computer_definition() { | |||
@@ -78,62 +75,68 @@ public class MeasureComputerDefinitionImplTest { | |||
@Test | |||
public void fail_with_NPE_when_null_input_metrics() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Input metrics cannot be null"); | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics((String[]) null) | |||
.setOutputMetrics("comment_density_1", "comment_density_2"); | |||
assertThatThrownBy(() -> { | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics((String[]) null) | |||
.setOutputMetrics("comment_density_1", "comment_density_2"); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Input metrics cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_one_input_metric_is_null() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Null metric is not allowed"); | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", null) | |||
.setOutputMetrics("comment_density_1", "comment_density_2"); | |||
assertThatThrownBy(() -> { | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", null) | |||
.setOutputMetrics("comment_density_1", "comment_density_2"); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Null metric is not allowed"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_no_output_metrics() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Output metrics cannot be null"); | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.build(); | |||
assertThatThrownBy(() -> { | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.build(); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Output metrics cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_null_output_metrics() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Output metrics cannot be null"); | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics((String[]) null); | |||
assertThatThrownBy(() -> { | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics((String[]) null); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Output metrics cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_one_output_metric_is_null() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Null metric is not allowed"); | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics("comment_density_1", null); | |||
assertThatThrownBy(() -> { | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics("comment_density_1", null); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Null metric is not allowed"); | |||
} | |||
@Test | |||
public void fail_with_IAE_with_empty_output_metrics() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("At least one output metric must be defined"); | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics(); | |||
assertThatThrownBy(() -> { | |||
new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics(); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("At least one output metric must be defined"); | |||
} | |||
@Test |
@@ -19,17 +19,14 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.api.measurecomputer; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.measure.Measure; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class MeasureImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void get_int_value() { | |||
@@ -39,11 +36,12 @@ public class MeasureImplTest { | |||
@Test | |||
public void fail_with_ISE_when_not_int_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Value can not be converted to int because current value type is a DOUBLE"); | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1d, 1)); | |||
measure.getIntValue(); | |||
assertThatThrownBy(() -> { | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1d, 1)); | |||
measure.getIntValue(); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Value can not be converted to int because current value type is a DOUBLE"); | |||
} | |||
@Test | |||
@@ -54,11 +52,12 @@ public class MeasureImplTest { | |||
@Test | |||
public void fail_with_ISE_when_not_double_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Value can not be converted to double because current value type is a INT"); | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1)); | |||
measure.getDoubleValue(); | |||
assertThatThrownBy(() -> { | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1)); | |||
measure.getDoubleValue(); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Value can not be converted to double because current value type is a INT"); | |||
} | |||
@Test | |||
@@ -69,11 +68,12 @@ public class MeasureImplTest { | |||
@Test | |||
public void fail_with_ISE_when_not_long_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Value can not be converted to long because current value type is a STRING"); | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create("value")); | |||
measure.getLongValue(); | |||
assertThatThrownBy(() -> { | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create("value")); | |||
measure.getLongValue(); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Value can not be converted to long because current value type is a STRING"); | |||
} | |||
@Test | |||
@@ -84,11 +84,12 @@ public class MeasureImplTest { | |||
@Test | |||
public void fail_with_ISE_when_not_string_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Value can not be converted to string because current value type is a LONG"); | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1L)); | |||
measure.getStringValue(); | |||
assertThatThrownBy(() -> { | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1L)); | |||
measure.getStringValue(); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Value can not be converted to string because current value type is a LONG"); | |||
} | |||
@Test | |||
@@ -99,34 +100,32 @@ public class MeasureImplTest { | |||
@Test | |||
public void fail_with_ISE_when_not_boolean_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Value can not be converted to boolean because current value type is a DOUBLE"); | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1d, 1)); | |||
measure.getBooleanValue(); | |||
assertThatThrownBy(() -> { | |||
MeasureImpl measure = new MeasureImpl(Measure.newMeasureBuilder().create(1d, 1)); | |||
measure.getBooleanValue(); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Value can not be converted to boolean because current value type is a DOUBLE"); | |||
} | |||
@Test | |||
public void fail_with_ISE_when_creating_measure_with_no_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Only following types are allowed [BOOLEAN, INT, LONG, DOUBLE, STRING]"); | |||
new MeasureImpl(Measure.newMeasureBuilder().createNoValue()); | |||
assertThatThrownBy(() -> new MeasureImpl(Measure.newMeasureBuilder().createNoValue())) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Only following types are allowed [BOOLEAN, INT, LONG, DOUBLE, STRING]"); | |||
} | |||
@Test | |||
public void fail_with_ISE_when_creating_measure_with_not_allowed_value() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Only following types are allowed [BOOLEAN, INT, LONG, DOUBLE, STRING]"); | |||
new MeasureImpl(Measure.newMeasureBuilder().create(Measure.Level.ERROR)); | |||
assertThatThrownBy(() -> new MeasureImpl(Measure.newMeasureBuilder().create(Measure.Level.ERROR))) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Only following types are allowed [BOOLEAN, INT, LONG, DOUBLE, STRING]"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_creating_measure_with_null_measure() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Measure couldn't be null"); | |||
new MeasureImpl(null); | |||
assertThatThrownBy(() -> new MeasureImpl(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Measure couldn't be null"); | |||
} | |||
} |
@@ -19,33 +19,27 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.api.posttask; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.ce.posttask.CeTask; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class CeTaskImplTest { | |||
private static final String SOME_ID = "some id"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructor_throws_NPE_if_id_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("id can not be null"); | |||
new CeTaskImpl(null, CeTask.Status.SUCCESS); | |||
assertThatThrownBy(() -> new CeTaskImpl(null, CeTask.Status.SUCCESS)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessageContaining("id can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_status_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("status can not be null"); | |||
new CeTaskImpl(SOME_ID, null); | |||
assertThatThrownBy(() -> new CeTaskImpl(SOME_ID, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("status can not be null"); | |||
} | |||
@Test |
@@ -22,13 +22,12 @@ package org.sonar.ce.task.projectanalysis.api.posttask; | |||
import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.ce.posttask.QualityGate; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class ConditionImplTest { | |||
@@ -36,8 +35,6 @@ public class ConditionImplTest { | |||
private static final String ERROR_THRESHOLD = "error threshold"; | |||
private static final String VALUE = "value"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private ConditionImpl.Builder builder = ConditionImpl.newBuilder() | |||
.setStatus(QualityGate.EvaluationStatus.OK) | |||
@@ -50,40 +47,36 @@ public class ConditionImplTest { | |||
public void build_throws_NPE_if_status_is_null() { | |||
builder.setStatus(null); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("status can not be null"); | |||
builder.build(); | |||
assertThatThrownBy(() -> builder.build()) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("status can not be null"); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_metricKey_is_null() { | |||
builder.setMetricKey(null); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("metricKey can not be null"); | |||
builder.build(); | |||
assertThatThrownBy(() -> builder.build()) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("metricKey can not be null"); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_operator_is_null() { | |||
builder.setOperator(null); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("operator can not be null"); | |||
builder.build(); | |||
assertThatThrownBy(() -> builder.build()) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("operator can not be null"); | |||
} | |||
@Test | |||
public void build_throws_NPE_if_error_threshold_is_null() { | |||
builder.setErrorThreshold(null); | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("errorThreshold can not be null"); | |||
builder.build(); | |||
assertThatThrownBy(() -> builder.build()) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("errorThreshold can not be null"); | |||
} | |||
@Test | |||
@@ -91,10 +84,9 @@ public class ConditionImplTest { | |||
builder.setStatus(QualityGate.EvaluationStatus.NO_VALUE).setValue(null); | |||
ConditionImpl condition = builder.build(); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("There is no value when status is NO_VALUE"); | |||
condition.getValue(); | |||
assertThatThrownBy(condition::getValue) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("There is no value when status is NO_VALUE"); | |||
} | |||
@DataProvider | |||
@@ -116,20 +108,18 @@ public class ConditionImplTest { | |||
builder.setStatus(status) | |||
.setValue(null); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("value can not be null when status is not NO_VALUE"); | |||
builder.build(); | |||
assertThatThrownBy(() -> builder.build()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("value can not be null when status is not NO_VALUE"); | |||
} | |||
@Test | |||
public void build_throws_IAE_if_value_is_not_null_but_status_is_NO_VALUE() { | |||
builder.setStatus(QualityGate.EvaluationStatus.NO_VALUE); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("value must be null when status is NO_VALUE"); | |||
builder.build(); | |||
assertThatThrownBy(() -> builder.build()) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("value must be null when status is NO_VALUE"); | |||
} | |||
@Test |
@@ -24,9 +24,7 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Collections; | |||
import java.util.Map; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.ce.posttask.QualityGate; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
@@ -35,6 +33,7 @@ import org.sonar.ce.task.projectanalysis.qualitygate.ConditionStatus; | |||
import static com.google.common.collect.ImmutableMap.of; | |||
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.when; | |||
@@ -46,26 +45,22 @@ public class ConditionToConditionTest { | |||
private static final String SOME_VALUE = "some value"; | |||
private static final ConditionStatus SOME_CONDITION_STATUS = ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, SOME_VALUE); | |||
private static final Condition SOME_CONDITION = new Condition(newMetric(METRIC_KEY), Condition.Operator.LESS_THAN.getDbValue(), ERROR_THRESHOLD); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void apply_throws_NPE_if_Condition_argument_is_null() { | |||
ConditionToCondition underTest = new ConditionToCondition(NO_STATUS_PER_CONDITIONS); | |||
expectedException.expect(NullPointerException.class); | |||
underTest.apply(null); | |||
assertThatThrownBy(() -> underTest.apply(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void apply_throws_ISE_if_there_is_no_ConditionStatus_for_Condition_argument() { | |||
ConditionToCondition underTest = new ConditionToCondition(NO_STATUS_PER_CONDITIONS); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Missing ConditionStatus for condition on metric key " + METRIC_KEY); | |||
underTest.apply(SOME_CONDITION); | |||
assertThatThrownBy(() -> underTest.apply(SOME_CONDITION)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Missing ConditionStatus for condition on metric key " + METRIC_KEY); | |||
} | |||
@Test | |||
@@ -112,10 +107,9 @@ public class ConditionToConditionTest { | |||
QualityGate.Condition res = underTest.apply(otherCondition); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("There is no value when status is NO_VALUE"); | |||
res.getValue(); | |||
assertThatThrownBy(res::getValue) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("There is no value when status is NO_VALUE"); | |||
} | |||
@DataProvider |
@@ -19,42 +19,36 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.api.posttask; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class ProjectImplTest { | |||
private static final String SOME_UUID = "some uuid"; | |||
private static final String SOME_KEY = "some key"; | |||
private static final String SOME_NAME = "some name"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructor_throws_NPE_if_uuid_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("uuid can not be null"); | |||
new ProjectImpl(null, SOME_KEY, SOME_NAME); | |||
assertThatThrownBy(() -> new ProjectImpl(null, SOME_KEY, SOME_NAME)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("uuid can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_key_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("key can not be null"); | |||
new ProjectImpl(SOME_UUID, null, SOME_NAME); | |||
assertThatThrownBy(() -> new ProjectImpl(SOME_UUID, null, SOME_NAME)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("key can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_name_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("name can not be null"); | |||
new ProjectImpl(SOME_UUID, SOME_KEY, null); | |||
assertThatThrownBy(() -> new ProjectImpl(SOME_UUID, SOME_KEY, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("name can not be null"); | |||
} | |||
@Test |
@@ -22,12 +22,11 @@ package org.sonar.ce.task.projectanalysis.api.posttask; | |||
import com.google.common.collect.ImmutableList; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.ce.posttask.QualityGate; | |||
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.when; | |||
@@ -36,42 +35,36 @@ public class QualityGateImplTest { | |||
private static final String SOME_NAME = "some name"; | |||
private static final QualityGate.Status SOME_STATUS = QualityGate.Status.OK; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private QualityGate.Condition condition = mock(QualityGate.Condition.class); | |||
private QualityGateImpl underTest = new QualityGateImpl(SOME_ID, SOME_NAME, SOME_STATUS, ImmutableList.of(condition)); | |||
@Test | |||
public void constructor_throws_NPE_if_id_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("id can not be null"); | |||
new QualityGateImpl(null, SOME_NAME, SOME_STATUS, Collections.emptyList()); | |||
assertThatThrownBy(() -> new QualityGateImpl(null, SOME_NAME, SOME_STATUS, Collections.emptyList())) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("id can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_name_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("name can not be null"); | |||
new QualityGateImpl(SOME_ID, null, SOME_STATUS, Collections.emptyList()); | |||
assertThatThrownBy(() -> new QualityGateImpl(SOME_ID, null, SOME_STATUS, Collections.emptyList())) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("name can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_status_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("status can not be null"); | |||
new QualityGateImpl(SOME_ID, SOME_NAME, null, Collections.emptyList()); | |||
assertThatThrownBy(() -> new QualityGateImpl(SOME_ID, SOME_NAME, null, Collections.emptyList())) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("status can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_conditions_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("conditions can not be null"); | |||
new QualityGateImpl(SOME_ID, SOME_NAME, SOME_STATUS, null); | |||
assertThatThrownBy(() -> new QualityGateImpl(SOME_ID, SOME_NAME, SOME_STATUS, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("conditions can not be null"); | |||
} | |||
@Test |
@@ -23,12 +23,14 @@ import java.io.File; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class BatchReportDirectoryHolderImplTest { | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
public void getDirectory_throws_ISE_if_holder_is_empty() { | |||
new BatchReportDirectoryHolderImpl().getDirectory(); | |||
assertThatThrownBy(() -> new BatchReportDirectoryHolderImpl().getDirectory()) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test |
@@ -33,6 +33,7 @@ import org.sonar.scanner.protocol.output.ScannerReportWriter; | |||
import static com.google.common.collect.ImmutableList.of; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class BatchReportReaderImplTest { | |||
private static final int COMPONENT_REF = 1; | |||
@@ -61,9 +62,10 @@ public class BatchReportReaderImplTest { | |||
writer = new ScannerReportWriter(holder.getDirectory()); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
public void readMetadata_throws_ISE_if_no_metadata() { | |||
underTest.readMetadata(); | |||
assertThatThrownBy(() -> underTest.readMetadata()) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -134,9 +136,10 @@ public class BatchReportReaderImplTest { | |||
assertThat(underTest.readChangesets(COMPONENT_REF)).isNotSameAs(underTest.readChangesets(COMPONENT_REF)); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
public void readComponent_throws_ISE_if_file_does_not_exist() { | |||
underTest.readComponent(COMPONENT_REF); | |||
assertThatThrownBy(() -> underTest.readComponent(COMPONENT_REF)) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test |
@@ -21,7 +21,6 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.MessageException; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.ce.task.projectanalysis.analysis.Branch; | |||
@@ -29,13 +28,12 @@ import org.sonar.db.component.BranchDto; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
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.times; | |||
import static org.mockito.Mockito.verify; | |||
public class BranchLoaderTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public AnalysisMetadataHolderRule metadataHolder = new AnalysisMetadataHolderRule(); | |||
@@ -46,10 +44,9 @@ public class BranchLoaderTest { | |||
.setBranchName("bar") | |||
.build(); | |||
expectedException.expect(MessageException.class); | |||
expectedException.expectMessage("Current edition does not support branch feature"); | |||
new BranchLoader(metadataHolder).load(metadata); | |||
assertThatThrownBy(() -> new BranchLoader(metadataHolder).load(metadata)) | |||
.isInstanceOf(MessageException.class) | |||
.hasMessage("Current edition does not support branch feature"); | |||
} | |||
@Test |
@@ -21,14 +21,13 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component.Status; | |||
import static com.google.common.base.Strings.repeat; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.assertj.core.api.Assertions.fail; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
@@ -39,8 +38,6 @@ public class ComponentImplTest { | |||
static final String KEY = "KEY"; | |||
static final String UUID = "UUID"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void verify_key_uuid_and_name() { | |||
@@ -53,56 +50,51 @@ public class ComponentImplTest { | |||
@Test | |||
public void builder_throws_NPE_if_component_arg_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(null); | |||
assertThatThrownBy(() -> builder(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void builder_throws_NPE_if_status_arg_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(FILE).setStatus(null); | |||
assertThatThrownBy(() -> builder(FILE).setStatus(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void builder_throws_NPE_if_status_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(Component.Type.DIRECTORY) | |||
.setName("DIR") | |||
.setDbKey(KEY) | |||
.setUuid(UUID) | |||
.setReportAttributes(ReportAttributes.newBuilder(1).build()) | |||
.build(); | |||
assertThatThrownBy(() -> { | |||
builder(Component.Type.DIRECTORY) | |||
.setName("DIR") | |||
.setDbKey(KEY) | |||
.setUuid(UUID) | |||
.setReportAttributes(ReportAttributes.newBuilder(1).build()) | |||
.build(); | |||
}) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void set_key_throws_NPE_if_component_arg_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(FILE).setUuid(null); | |||
assertThatThrownBy(() -> builder(FILE).setUuid(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void set_uuid_throws_NPE_if_component_arg_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(FILE).setDbKey(null); | |||
assertThatThrownBy(() -> builder(FILE).setDbKey(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void build_without_key_throws_NPE_if_component_arg_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(FILE).setUuid("ABCD").build(); | |||
assertThatThrownBy(() -> builder(FILE).setUuid("ABCD").build()) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void build_without_uuid_throws_NPE_if_component_arg_is_Null() { | |||
expectedException.expect(NullPointerException.class); | |||
builder(FILE).setDbKey(KEY).build(); | |||
assertThatThrownBy(() -> builder(FILE).setDbKey(KEY).build()) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -31,7 +31,6 @@ import java.util.function.Function; | |||
import java.util.function.UnaryOperator; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.ExternalResource; | |||
import org.sonar.ce.task.projectanalysis.analysis.Branch; | |||
import org.sonar.core.component.ComponentKeys; | |||
@@ -41,6 +40,7 @@ import org.sonar.server.project.Project; | |||
import static com.google.common.base.Preconditions.checkArgument; | |||
import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.junit.Assert.fail; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
@@ -64,8 +64,6 @@ public class ComponentTreeBuilderTest { | |||
private static final ProjectAttributes SOME_PROJECT_ATTRIBUTES = new ProjectAttributes( | |||
randomAlphabetic(20), new Random().nextBoolean() ? null : randomAlphabetic(12), "1def5123"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public ScannerComponentProvider scannerComponentProvider = new ScannerComponentProvider(); | |||
@@ -717,10 +715,9 @@ public class ComponentTreeBuilderTest { | |||
.setType(FILE) | |||
.setProjectRelativePath("src/js/Foo.js")); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("File 'src/js/Foo.js' has no line"); | |||
call(project); | |||
assertThatThrownBy(() -> call(project)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("File 'src/js/Foo.js' has no line"); | |||
} | |||
@Test | |||
@@ -736,10 +733,9 @@ public class ComponentTreeBuilderTest { | |||
.setProjectRelativePath("src/js/Foo.js") | |||
.setLines(0)); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("File 'src/js/Foo.js' has no line"); | |||
call(project); | |||
assertThatThrownBy(() -> call(project)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("File 'src/js/Foo.js' has no line"); | |||
} | |||
@Test | |||
@@ -755,10 +751,9 @@ public class ComponentTreeBuilderTest { | |||
.setProjectRelativePath("src/js/Foo.js") | |||
.setLines(-10)); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("File 'src/js/Foo.js' has no line"); | |||
call(project); | |||
assertThatThrownBy(() -> call(project)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("File 'src/js/Foo.js' has no line"); | |||
} | |||
private static class ScannerComponentProvider extends ExternalResource implements Function<Integer, ScannerReport.Component> { |
@@ -28,9 +28,7 @@ import java.util.Arrays; | |||
import java.util.Set; | |||
import java.util.stream.Collectors; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.component.Component.Type; | |||
@@ -40,14 +38,13 @@ import static com.google.common.base.Predicates.not; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static java.util.Arrays.asList; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class CrawlerDepthLimitTest { | |||
private static final Set<Type> REPORT_TYPES = Arrays.stream(Type.values()).filter(Type::isReportType).collect(Collectors.toSet()); | |||
private static final Set<Type> VIEWS_TYPES = Arrays.stream(Type.values()).filter(Type::isViewsType).collect(Collectors.toSet()); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void PROJECT_isSameAs_only_PROJECT_type() { | |||
@@ -283,10 +280,9 @@ public class CrawlerDepthLimitTest { | |||
@Test | |||
@UseDataProvider("viewsTypes") | |||
public void reportMaxDepth_throws_IAE_if_type_is_views(Type viewsType) { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("A Report max depth must be a report type"); | |||
CrawlerDepthLimit.reportMaxDepth(viewsType); | |||
assertThatThrownBy(() -> CrawlerDepthLimit.reportMaxDepth(viewsType)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("A Report max depth must be a report type"); | |||
} | |||
@Test | |||
@@ -298,10 +294,9 @@ public class CrawlerDepthLimitTest { | |||
@Test | |||
@UseDataProvider("reportTypes") | |||
public void withViewsMaxDepth_throws_IAE_if_type_is_report(Type reportType) { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("A Views max depth must be a views type"); | |||
CrawlerDepthLimit.reportMaxDepth(reportType).withViewsMaxDepth(reportType); | |||
assertThatThrownBy(() -> CrawlerDepthLimit.reportMaxDepth(reportType).withViewsMaxDepth(reportType)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("A Views max depth must be a views type"); | |||
} | |||
@DataProvider |
@@ -19,9 +19,7 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.db.component.BranchDto; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
@@ -33,8 +31,6 @@ public class DefaultBranchImplTest { | |||
private static final String PROJECT_KEY = "P"; | |||
private static final ScannerReport.Component FILE = ScannerReport.Component.newBuilder().setType(ComponentType.FILE).setProjectRelativePath("src/Foo.js").build(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void default_branch_represents_the_project() { |
@@ -20,16 +20,13 @@ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import com.google.common.collect.ImmutableSet; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class DisabledComponentsHolderImplTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
DisabledComponentsHolderImpl underTest = new DisabledComponentsHolderImpl(); | |||
@@ -44,15 +41,15 @@ public class DisabledComponentsHolderImplTest { | |||
public void setUuids_fails_if_called_twice() { | |||
underTest.setUuids(ImmutableSet.of("U1", "U2")); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("UUIDs have already been set in repository"); | |||
underTest.setUuids(ImmutableSet.of("U1", "U2")); | |||
assertThatThrownBy(() -> underTest.setUuids(ImmutableSet.of("U1", "U2"))) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("UUIDs have already been set in repository"); | |||
} | |||
@Test | |||
public void getUuids_fails_if_not_initialized() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("UUIDs have not been set in repository"); | |||
underTest.getUuids(); | |||
assertThatThrownBy(() -> underTest.getUuids()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("UUIDs have not been set in repository"); | |||
} | |||
} |
@@ -19,16 +19,13 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class FileAttributesTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void create_production_file() { | |||
@@ -59,16 +56,16 @@ public class FileAttributesTest { | |||
@Test | |||
public void fail_with_IAE_when_lines_is_0() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Number of lines must be greater than zero"); | |||
new FileAttributes(true, "java", 0); | |||
assertThatThrownBy(() -> new FileAttributes(true, "java", 0)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Number of lines must be greater than zero"); | |||
} | |||
@Test | |||
public void fail_with_IAE_when_lines_is_less_than_0() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Number of lines must be greater than zero"); | |||
new FileAttributes(true, "java", -10); | |||
assertThatThrownBy(() -> new FileAttributes(true, "java", -10)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Number of lines must be greater than zero"); | |||
} | |||
@Test |
@@ -22,7 +22,6 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.impl.utils.TestSystem2; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
@@ -32,7 +31,6 @@ import org.sonar.db.project.ProjectDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verify; | |||
import static org.mockito.Mockito.verifyNoInteractions; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
@@ -53,8 +51,6 @@ public class ProjectPersisterTest { | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | |||
@Rule | |||
public ExpectedException exception = ExpectedException.none(); | |||
public TestSystem2 system2 = new TestSystem2(); | |||
private ProjectPersister underTest = new ProjectPersister(dbTester.getDbClient(), treeRootHolder, system2); |
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
@@ -41,9 +42,10 @@ public class ReportPostOrderDepthTraversalTypeAwareCrawlerTest { | |||
private final DepthTraversalTypeAwareCrawler directoryCrawler = new DepthTraversalTypeAwareCrawler(directoryVisitor); | |||
private final DepthTraversalTypeAwareCrawler fileCrawler = new DepthTraversalTypeAwareCrawler(fileVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
fileCrawler.visit(null); | |||
assertThatThrownBy(() -> fileCrawler.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
@@ -42,9 +43,10 @@ public class ReportPreOrderDepthTraversalTypeAwareCrawlerTest { | |||
private final DepthTraversalTypeAwareCrawler directoryCrawler = new DepthTraversalTypeAwareCrawler(directoryVisitor); | |||
private final DepthTraversalTypeAwareCrawler fileCrawler = new DepthTraversalTypeAwareCrawler(fileVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
fileCrawler.visit(null); | |||
assertThatThrownBy(() -> fileCrawler.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -20,12 +20,11 @@ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import java.util.Arrays; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.mockito.InOrder; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.inOrder; | |||
@@ -38,8 +37,6 @@ import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order | |||
public class ReportVisitorsCrawlerTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private static final Component FILE_5 = component(FILE, 5); | |||
private static final Component DIRECTORY_4 = component(DIRECTORY, 4, FILE_5); | |||
@@ -104,21 +101,23 @@ public class ReportVisitorsCrawlerTest { | |||
@Test | |||
public void fail_with_IAE_when_visitor_is_not_path_aware_or_type_aware() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only TypeAwareVisitor and PathAwareVisitor can be used"); | |||
ComponentVisitor componentVisitor = new ComponentVisitor() { | |||
@Override | |||
public Order getOrder() { | |||
return PRE_ORDER; | |||
} | |||
assertThatThrownBy(() -> { | |||
ComponentVisitor componentVisitor = new ComponentVisitor() { | |||
@Override | |||
public Order getOrder() { | |||
return PRE_ORDER; | |||
} | |||
@Override | |||
public CrawlerDepthLimit getMaxDepth() { | |||
@Override | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return CrawlerDepthLimit.FILE; | |||
} | |||
}; | |||
new VisitorsCrawler(Arrays.asList(componentVisitor)); | |||
}; | |||
new VisitorsCrawler(Arrays.asList(componentVisitor)); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only TypeAwareVisitor and PathAwareVisitor can be used"); | |||
} | |||
private static Component component(final Component.Type type, final int ref, final Component... children) { |
@@ -23,6 +23,7 @@ import java.util.Arrays; | |||
import org.junit.Test; | |||
import org.mockito.InOrder; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.inOrder; | |||
import static org.mockito.Mockito.never; | |||
import static org.mockito.Mockito.spy; | |||
@@ -46,10 +47,12 @@ public class ReportVisitorsCrawlerWithPostOrderTypeAwareVisitorTest { | |||
}); | |||
private final InOrder inOrder = inOrder(spyProjectVisitor, spyDirectoryVisitor, spyFileVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
VisitorsCrawler underTest = newVisitorsCrawler(spyFileVisitor); | |||
underTest.visit(null); | |||
assertThatThrownBy(() -> underTest.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -23,6 +23,7 @@ import java.util.Arrays; | |||
import org.junit.Test; | |||
import org.mockito.InOrder; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.inOrder; | |||
import static org.mockito.Mockito.never; | |||
import static org.mockito.Mockito.spy; | |||
@@ -30,7 +31,6 @@ import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTO | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER; | |||
public class ReportVisitorsCrawlerWithPreOrderTypeAwareVisitorTest { | |||
private static final Component FILE_5 = component(FILE, 5); | |||
@@ -46,10 +46,12 @@ public class ReportVisitorsCrawlerWithPreOrderTypeAwareVisitorTest { | |||
}); | |||
private final InOrder inOrder = inOrder(spyProjectVisitor, spyDirectoryVisitor, spyFileVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
VisitorsCrawler underTest = newVisitorsCrawler(spyFileVisitor); | |||
underTest.visit(null); | |||
assertThatThrownBy(() -> underTest.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -19,11 +19,10 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTORY; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT; | |||
@@ -46,49 +45,43 @@ public class TreeRootHolderImplTest { | |||
.build()) | |||
.build(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private TreeRootHolderImpl underTest = new TreeRootHolderImpl(); | |||
@Test | |||
public void setRoots_throws_NPE_if_root_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("root can not be null"); | |||
underTest.setRoots(null, DUMB_PROJECT); | |||
assertThatThrownBy(() -> underTest.setRoots(null, DUMB_PROJECT)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("root can not be null"); | |||
} | |||
@Test | |||
public void setRoots_throws_NPE_if_reportRoot_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("root can not be null"); | |||
underTest.setRoots(DUMB_PROJECT, null); | |||
assertThatThrownBy(() -> underTest.setRoots(DUMB_PROJECT, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessageContaining("root can not be null"); | |||
} | |||
@Test | |||
public void setRoot_throws_ISE_when_called_twice() { | |||
underTest.setRoots(DUMB_PROJECT, DUMB_PROJECT); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("root can not be set twice in holder"); | |||
underTest.setRoots(null, DUMB_PROJECT); | |||
assertThatThrownBy(() -> underTest.setRoots(null, DUMB_PROJECT)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("root can not be set twice in holder"); | |||
} | |||
@Test | |||
public void getRoot_throws_ISE_if_root_has_not_been_set_yet() { | |||
expectNotInitialized_ISE(); | |||
underTest.getRoot(); | |||
assertThatThrownBy(() -> underTest.getRoot()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Holder has not been initialized yet"); | |||
} | |||
@Test | |||
public void getComponentByRef_throws_ISE_if_root_has_not_been_set() { | |||
expectNotInitialized_ISE(); | |||
underTest.getComponentByRef(12); | |||
assertThatThrownBy(() -> underTest.getComponentByRef(12)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Holder has not been initialized yet"); | |||
} | |||
@Test | |||
@@ -113,10 +106,9 @@ public class TreeRootHolderImplTest { | |||
public void getComponentByRef_throws_IAE_if_holder_does_not_contain_specified_component() { | |||
underTest.setRoots(SOME_REPORT_COMPONENT_TREE, DUMB_PROJECT); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Component with ref '6' can't be found"); | |||
underTest.getComponentByRef(6); | |||
assertThatThrownBy(() -> underTest.getComponentByRef(6)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Component with ref '6' can't be found"); | |||
} | |||
@Test | |||
@@ -130,10 +122,9 @@ public class TreeRootHolderImplTest { | |||
public void getComponentByRef_throws_IAE_if_holder_contains_View_tree() { | |||
underTest.setRoots(SOME_VIEWS_COMPONENT_TREE, DUMB_PROJECT); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Component with ref '1' can't be found"); | |||
underTest.getComponentByRef(1); | |||
assertThatThrownBy(() -> underTest.getComponentByRef(1)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Component with ref '1' can't be found"); | |||
} | |||
@Test | |||
@@ -150,9 +141,9 @@ public class TreeRootHolderImplTest { | |||
@Test | |||
public void getSize_throws_ISE_if_not_initialized() { | |||
expectNotInitialized_ISE(); | |||
underTest.getSize(); | |||
assertThatThrownBy(() -> underTest.getSize()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Holder has not been initialized yet"); | |||
} | |||
@Test | |||
@@ -160,10 +151,4 @@ public class TreeRootHolderImplTest { | |||
underTest.setRoots(SOME_REPORT_COMPONENT_TREE, DUMB_PROJECT); | |||
assertThat(underTest.getSize()).isEqualTo(3); | |||
} | |||
private void expectNotInitialized_ISE() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Holder has not been initialized yet"); | |||
} | |||
} |
@@ -21,13 +21,17 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER; | |||
public class TypeAwareVisitorAdapterTest { | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void non_null_max_depth_fast_fail() { | |||
new TypeAwareVisitorAdapter(null, POST_ORDER) { | |||
}; | |||
assertThatThrownBy(() -> { | |||
new TypeAwareVisitorAdapter(null, POST_ORDER) { | |||
}; | |||
}) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
} |
@@ -19,18 +19,15 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.resources.Qualifiers; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.ViewAttributes.Type.APPLICATION; | |||
import static org.sonar.ce.task.projectanalysis.component.ViewAttributes.Type.PORTFOLIO; | |||
public class ViewAttributesTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private ViewAttributes underTest; | |||
@@ -58,9 +55,8 @@ public class ViewAttributesTest { | |||
@Test | |||
public void fail_if_unknown_view_qualifier() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Qualifier 'TRK' is not supported"); | |||
ViewAttributes.Type.fromQualifier(Qualifiers.PROJECT); | |||
assertThatThrownBy(() -> ViewAttributes.Type.fromQualifier(Qualifiers.PROJECT)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Qualifier 'TRK' is not supported"); | |||
} | |||
} |
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW; | |||
@@ -44,9 +45,10 @@ public class ViewsPostOrderDepthTraversalTypeAwareCrawlerTest { | |||
private final DepthTraversalTypeAwareCrawler subViewCrawler = new DepthTraversalTypeAwareCrawler(subViewVisitor); | |||
private final DepthTraversalTypeAwareCrawler projectViewCrawler = new DepthTraversalTypeAwareCrawler(projectViewVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
projectViewCrawler.visit(null); | |||
assertThatThrownBy(() -> projectViewCrawler.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.component; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT_VIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW; | |||
@@ -44,9 +45,10 @@ public class ViewsPreOrderDepthTraversalTypeAwareCrawlerTest { | |||
private final DepthTraversalTypeAwareCrawler subViewCrawler = new DepthTraversalTypeAwareCrawler(subViewVisitor); | |||
private final DepthTraversalTypeAwareCrawler projectViewCrawler = new DepthTraversalTypeAwareCrawler(projectViewVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
projectViewCrawler.visit(null); | |||
assertThatThrownBy(() -> projectViewCrawler.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -20,12 +20,11 @@ | |||
package org.sonar.ce.task.projectanalysis.component; | |||
import java.util.Arrays; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.mockito.InOrder; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.inOrder; | |||
@@ -38,8 +37,6 @@ import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order | |||
public class ViewsVisitorsCrawlerTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private static final Component PROJECT_VIEW_5 = component(PROJECT_VIEW, 5); | |||
private static final Component SUBVIEW_4 = component(SUBVIEW, 4, PROJECT_VIEW_5); | |||
@@ -104,21 +101,23 @@ public class ViewsVisitorsCrawlerTest { | |||
@Test | |||
public void fail_with_IAE_when_visitor_is_not_path_aware_or_type_aware() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only TypeAwareVisitor and PathAwareVisitor can be used"); | |||
ComponentVisitor componentVisitor = new ComponentVisitor() { | |||
@Override | |||
public Order getOrder() { | |||
return PRE_ORDER; | |||
} | |||
@Override | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return CrawlerDepthLimit.PROJECT_VIEW; | |||
} | |||
}; | |||
new VisitorsCrawler(Arrays.asList(componentVisitor)); | |||
assertThatThrownBy(() -> { | |||
ComponentVisitor componentVisitor = new ComponentVisitor() { | |||
@Override | |||
public Order getOrder() { | |||
return PRE_ORDER; | |||
} | |||
@Override | |||
public CrawlerDepthLimit getMaxDepth() { | |||
return CrawlerDepthLimit.PROJECT_VIEW; | |||
} | |||
}; | |||
new VisitorsCrawler(Arrays.asList(componentVisitor)); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only TypeAwareVisitor and PathAwareVisitor can be used"); | |||
} | |||
@Test |
@@ -30,7 +30,7 @@ import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.SUBVIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.VIEW; | |||
import static org.sonar.ce.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class ViewsVisitorsCrawlerWithPostOrderTypeAwareVisitorTest { | |||
private static final Component PROJECT_VIEW_5 = component(PROJECT_VIEW, 5); | |||
@@ -48,10 +48,11 @@ public class ViewsVisitorsCrawlerWithPostOrderTypeAwareVisitorTest { | |||
}); | |||
private final InOrder inOrder = inOrder(spyViewVisitor, spySubViewVisitor, spyProjectViewVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
VisitorsCrawler underTest = newVisitorsCrawler(spyProjectViewVisitor); | |||
underTest.visit(null); | |||
assertThatThrownBy(() -> underTest.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -23,6 +23,7 @@ import java.util.Arrays; | |||
import org.junit.Test; | |||
import org.mockito.InOrder; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.inOrder; | |||
import static org.mockito.Mockito.never; | |||
import static org.mockito.Mockito.spy; | |||
@@ -48,10 +49,12 @@ public class ViewsVisitorsCrawlerWithPreOrderTypeAwareVisitorTest { | |||
}); | |||
private final InOrder inOrder = inOrder(spyViewVisitor, spySubViewVisitor, spyProjectViewVisitor); | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void visit_null_Component_throws_NPE() { | |||
VisitorsCrawler underTest = newVisitorsCrawler(spyProjectViewVisitor); | |||
underTest.visit(null); | |||
assertThatThrownBy(() -> underTest.visit(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -19,33 +19,27 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.duplication; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class CrossProjectDuplicateTest { | |||
private static final String FILE_KEY_1 = "file key 1"; | |||
private static final String FILE_KEY_2 = "file key 2"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructors_throws_NPE_if_fileKey_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("fileKey can not be null"); | |||
new CrossProjectDuplicate(null, new TextBlock(1, 1)); | |||
assertThatThrownBy(() -> new CrossProjectDuplicate(null, new TextBlock(1, 1))) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("fileKey can not be null"); | |||
} | |||
@Test | |||
public void constructors_throws_NPE_if_textBlock_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("textBlock of duplicate can not be null"); | |||
new CrossProjectDuplicate(FILE_KEY_1, null); | |||
assertThatThrownBy(() -> new CrossProjectDuplicate(FILE_KEY_1, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("textBlock of duplicate can not be null"); | |||
} | |||
@Test |
@@ -21,20 +21,18 @@ package org.sonar.ce.task.projectanalysis.duplication; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.utils.log.LogTester; | |||
import org.sonar.api.utils.log.LoggerLevel; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.ce.task.projectanalysis.analysis.Branch; | |||
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.when; | |||
public class CrossProjectDuplicationStatusHolderImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Rule | |||
public LogTester logTester = new LogTester(); | |||
@Rule | |||
@@ -101,10 +99,9 @@ public class CrossProjectDuplicationStatusHolderImplTest { | |||
@Test | |||
public void isEnabled_throws_ISE_when_start_have_not_been_called_before() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Flag hasn't been initialized, the start() should have been called before"); | |||
underTest.isEnabled(); | |||
assertThatThrownBy(() -> underTest.isEnabled()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessageContaining("Flag hasn't been initialized, the start() should have been called before"); | |||
} | |||
private static Branch newBranch(boolean supportsCrossProjectCpd) { |
@@ -24,15 +24,14 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import org.assertj.core.api.Assertions; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.util.WrapInSingleElementArray; | |||
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.when; | |||
@@ -42,26 +41,25 @@ public class DuplicationRepositoryImplTest { | |||
private static final Component FILE_COMPONENT_2 = ReportComponent.builder(Component.Type.FILE, 2).build(); | |||
private static final Duplication SOME_DUPLICATION = createDuplication(1, 2); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private DuplicationRepository underTest = new DuplicationRepositoryImpl(); | |||
@Test | |||
public void getDuplications_throws_NPE_if_Component_argument_is_null() { | |||
expectFileArgumentNPE(); | |||
underTest.getDuplications(null); | |||
assertThatThrownBy(() -> underTest.getDuplications(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("file can not be null"); | |||
} | |||
@Test | |||
@UseDataProvider("allComponentTypesButFile") | |||
public void getDuplications_throws_IAE_if_Component_type_is_not_FILE(Component.Type type) { | |||
expectFileTypeIAE(); | |||
Component component = mockComponentGetType(type); | |||
underTest.getDuplications(component); | |||
assertThatThrownBy(() -> { | |||
Component component = mockComponentGetType(type); | |||
underTest.getDuplications(component); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("type of file must be FILE"); | |||
} | |||
@Test | |||
@@ -71,27 +69,27 @@ public class DuplicationRepositoryImplTest { | |||
@Test | |||
public void add_throws_NPE_if_file_argument_is_null() { | |||
expectFileArgumentNPE(); | |||
underTest.add(null, SOME_DUPLICATION); | |||
assertThatThrownBy(() -> underTest.add(null, SOME_DUPLICATION)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("file can not be null"); | |||
} | |||
@Test | |||
public void addDuplication_inner_throws_NPE_if_duplication_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("duplication can not be null"); | |||
underTest.add(FILE_COMPONENT_1, null); | |||
assertThatThrownBy(() -> underTest.add(FILE_COMPONENT_1, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("duplication can not be null"); | |||
} | |||
@Test | |||
@UseDataProvider("allComponentTypesButFile") | |||
public void addDuplication_inner_throws_IAE_if_file_type_is_not_FILE(Component.Type type) { | |||
expectFileTypeIAE(); | |||
Component component = mockComponentGetType(type); | |||
underTest.add(component, SOME_DUPLICATION); | |||
assertThatThrownBy(() -> { | |||
Component component = mockComponentGetType(type); | |||
underTest.add(component, SOME_DUPLICATION); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("type of file must be FILE"); | |||
} | |||
@Test | |||
@@ -145,16 +143,6 @@ public class DuplicationRepositoryImplTest { | |||
assertThat(underTest.getDuplications(component)).isEmpty(); | |||
} | |||
private void expectFileArgumentNPE() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("file can not be null"); | |||
} | |||
private void expectFileTypeIAE() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("type of file must be FILE"); | |||
} | |||
private Component mockComponentGetType(Component.Type type) { | |||
Component component = mock(Component.class); | |||
when(component.getType()).thenReturn(type); |
@@ -23,13 +23,12 @@ import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.mock; | |||
public class DuplicationTest { | |||
@@ -41,55 +40,47 @@ public class DuplicationTest { | |||
private static final String FILE_KEY_1 = "1"; | |||
private static final String FILE_KEY_2 = "2"; | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructor_throws_NPE_if_original_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("original TextBlock can not be null"); | |||
new Duplication(null, Collections.emptyList()); | |||
assertThatThrownBy(() -> new Duplication(null, Collections.emptyList())) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("original TextBlock can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_duplicates_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("duplicates can not be null"); | |||
new Duplication(SOME_ORIGINAL_TEXTBLOCK, null); | |||
assertThatThrownBy(() -> new Duplication(SOME_ORIGINAL_TEXTBLOCK, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("duplicates can not be null"); | |||
} | |||
@Test | |||
public void constructor_throws_IAE_if_duplicates_is_empty() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("duplicates can not be empty"); | |||
new Duplication(SOME_ORIGINAL_TEXTBLOCK, Collections.emptyList()); | |||
assertThatThrownBy(() -> new Duplication(SOME_ORIGINAL_TEXTBLOCK, Collections.emptyList())) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("duplicates can not be empty"); | |||
} | |||
@Test | |||
public void constructor_throws_NPE_if_duplicates_contains_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("duplicates can not contain null"); | |||
new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(mock(Duplicate.class), null, mock(Duplicate.class))); | |||
assertThatThrownBy(() -> new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(mock(Duplicate.class), null, mock(Duplicate.class)))) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("duplicates can not contain null"); | |||
} | |||
@Test | |||
public void constructor_throws_IAE_if_duplicates_contains_InnerDuplicate_of_original() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("TextBlock of an InnerDuplicate can not be the original TextBlock"); | |||
new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(mock(Duplicate.class), new InnerDuplicate(SOME_ORIGINAL_TEXTBLOCK), mock(Duplicate.class))); | |||
assertThatThrownBy(() -> new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(mock(Duplicate.class), new InnerDuplicate(SOME_ORIGINAL_TEXTBLOCK), mock(Duplicate.class)))) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("TextBlock of an InnerDuplicate can not be the original TextBlock"); | |||
} | |||
@Test | |||
public void constructor_throws_IAE_when_attempting_to_sort_Duplicate_of_unkown_type() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Unsupported type of Duplicate " + MyDuplicate.class.getName()); | |||
new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new MyDuplicate(), new MyDuplicate())); | |||
assertThatThrownBy(() -> new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new MyDuplicate(), new MyDuplicate()))) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Unsupported type of Duplicate " + MyDuplicate.class.getName()); | |||
} | |||
private static final class MyDuplicate implements Duplicate { |
@@ -19,43 +19,37 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.duplication; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class InProjectDuplicateTest { | |||
private static final Component FILE_1 = ReportComponent.builder(Component.Type.FILE, 1).build(); | |||
private static final Component FILE_2 = ReportComponent.builder(Component.Type.FILE, 2).build(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructors_throws_NPE_if_file_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("file can not be null"); | |||
new InProjectDuplicate(null, new TextBlock(1, 1)); | |||
assertThatThrownBy(() -> new InProjectDuplicate(null, new TextBlock(1, 1))) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("file can not be null"); | |||
} | |||
@Test | |||
public void constructors_throws_NPE_if_textBlock_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("textBlock of duplicate can not be null"); | |||
new InProjectDuplicate(FILE_1, null); | |||
assertThatThrownBy(() -> new InProjectDuplicate(FILE_1, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("textBlock of duplicate can not be null"); | |||
} | |||
@Test | |||
public void constructors_throws_IAE_if_type_of_file_argument_is_not_FILE() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("file must be of type FILE"); | |||
new InProjectDuplicate(ReportComponent.builder(Component.Type.PROJECT, 1).build(), new TextBlock(1, 1)); | |||
assertThatThrownBy(() -> new InProjectDuplicate(ReportComponent.builder(Component.Type.PROJECT, 1).build(), new TextBlock(1, 1))) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("file must be of type FILE"); | |||
} | |||
@Test |
@@ -19,22 +19,18 @@ | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.duplication; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class InnerDuplicateTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructors_throws_NPE_if_textBlock_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("textBlock of duplicate can not be null"); | |||
new InnerDuplicate(null); | |||
assertThatThrownBy(() -> new InnerDuplicate(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("textBlock of duplicate can not be null"); | |||
} | |||
@Test |
@@ -24,30 +24,25 @@ import java.util.Arrays; | |||
import java.util.Collections; | |||
import java.util.List; | |||
import java.util.Random; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class TextBlockTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void constructor_throws_IAE_if_start_is_0() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("First line index must be >= 1"); | |||
new TextBlock(0, 2); | |||
assertThatThrownBy(() -> new TextBlock(0, 2)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("First line index must be >= 1"); | |||
} | |||
@Test | |||
public void constructor_throws_IAE_if_end_is_less_than_start() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Last line index must be >= first line index"); | |||
new TextBlock(1, 0); | |||
assertThatThrownBy(() -> new TextBlock(1, 0)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Last line index must be >= first line index"); | |||
} | |||
@Test |
@@ -26,6 +26,7 @@ import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.component.ViewsComponent; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.assertj.core.api.Assertions.fail; | |||
public class EventRepositoryImplTest { | |||
@@ -50,14 +51,16 @@ public class EventRepositoryImplTest { | |||
assertThat(underTest.getEvents(COMPONENT_2)).extracting("name").containsExactly(EVENT_2.getName()); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void add_throws_NPE_if_component_arg_is_null() { | |||
underTest.add(null, EVENT_1); | |||
assertThatThrownBy(() -> underTest.add(null, EVENT_1)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void add_throws_NPE_if_even_arg_is_null() { | |||
underTest.add(COMPONENT_1, null); | |||
assertThatThrownBy(() -> underTest.add(COMPONENT_1, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -22,6 +22,7 @@ package org.sonar.ce.task.projectanalysis.event; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class EventTest { | |||
@@ -29,14 +30,16 @@ public class EventTest { | |||
private static final String SOME_DATA = "some data"; | |||
private static final String SOME_DESCRIPTION = "some description"; | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void createAlert_fail_fast_null_check_on_null_name() { | |||
Event.createAlert(null, SOME_DATA, SOME_DESCRIPTION); | |||
assertThatThrownBy(() -> Event.createAlert(null, SOME_DATA, SOME_DESCRIPTION)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void createProfile_fail_fast_null_check_on_null_name() { | |||
Event.createProfile(null, SOME_DATA, SOME_DESCRIPTION); | |||
assertThatThrownBy(() -> Event.createProfile(null, SOME_DATA, SOME_DESCRIPTION)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -23,31 +23,27 @@ import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Arrays; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
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.when; | |||
@RunWith(DataProviderRunner.class) | |||
public class AddedFileRepositoryImplTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private AnalysisMetadataHolder analysisMetadataHolder = mock(AnalysisMetadataHolder.class); | |||
private AddedFileRepositoryImpl underTest = new AddedFileRepositoryImpl(analysisMetadataHolder); | |||
@Test | |||
public void isAdded_fails_with_NPE_if_component_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("component can't be null"); | |||
underTest.isAdded(null); | |||
assertThatThrownBy(() -> underTest.isAdded(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("component can't be null"); | |||
} | |||
@Test | |||
@@ -85,10 +81,9 @@ public class AddedFileRepositoryImplTest { | |||
@Test | |||
public void register_fails_with_NPE_if_component_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("component can't be null"); | |||
underTest.register(null); | |||
assertThatThrownBy(() -> underTest.register(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("component can't be null"); | |||
} | |||
@Test | |||
@@ -96,10 +91,9 @@ public class AddedFileRepositoryImplTest { | |||
public void register_fails_with_IAE_if_component_is_not_a_file(Component.Type anyTypeButFile) { | |||
Component component = newComponent(anyTypeButFile); | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("component must be a file"); | |||
underTest.register(component); | |||
assertThatThrownBy(() -> underTest.register(component)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("component must be a file"); | |||
} | |||
@DataProvider | |||
@@ -115,10 +109,9 @@ public class AddedFileRepositoryImplTest { | |||
when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true); | |||
Component component = newComponent(Component.Type.FILE); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("No file can be registered on first analysis"); | |||
underTest.register(component); | |||
assertThatThrownBy(() -> underTest.register(component)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("No file can be registered on first analysis"); | |||
} | |||
private static Component newComponent(Component.Type type) { |
@@ -20,13 +20,12 @@ | |||
package org.sonar.ce.task.projectanalysis.filemove; | |||
import java.util.Random; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ViewsComponent; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.assertj.core.api.Assertions.fail; | |||
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder; | |||
@@ -41,25 +40,20 @@ public class MutableMovedFilesRepositoryImplTest { | |||
}; | |||
private static final MovedFilesRepository.OriginalFile SOME_ORIGINAL_FILE = new MovedFilesRepository.OriginalFile("uuid for 100", "key for 100"); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private MutableMovedFilesRepositoryImpl underTest = new MutableMovedFilesRepositoryImpl(); | |||
@Test | |||
public void setOriginalFile_throws_NPE_when_file_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("file can't be null"); | |||
underTest.setOriginalFile(null, SOME_ORIGINAL_FILE); | |||
assertThatThrownBy(() -> underTest.setOriginalFile(null, SOME_ORIGINAL_FILE)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("file can't be null"); | |||
} | |||
@Test | |||
public void setOriginalFile_throws_NPE_when_originalFile_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("originalFile can't be null"); | |||
underTest.setOriginalFile(SOME_FILE, null); | |||
assertThatThrownBy(() -> underTest.setOriginalFile(SOME_FILE, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("originalFile can't be null"); | |||
} | |||
@Test | |||
@@ -80,11 +74,10 @@ public class MutableMovedFilesRepositoryImplTest { | |||
public void setOriginalFile_throws_ISE_if_settings_another_originalFile() { | |||
underTest.setOriginalFile(SOME_FILE, SOME_ORIGINAL_FILE); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Original file OriginalFile{uuid='uuid for 100', key='key for 100'} " + | |||
"already registered for file ReportComponent{ref=1, key='key_1', type=FILE}"); | |||
underTest.setOriginalFile(SOME_FILE, new MovedFilesRepository.OriginalFile("uudi", "key")); | |||
assertThatThrownBy(() -> underTest.setOriginalFile(SOME_FILE, new MovedFilesRepository.OriginalFile("uudi", "key"))) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessageContaining("Original file OriginalFile{uuid='uuid for 100', key='key for 100'} " + | |||
"already registered for file ReportComponent{ref=1, key='key_1', type=FILE}"); | |||
} | |||
@Test | |||
@@ -104,10 +97,9 @@ public class MutableMovedFilesRepositoryImplTest { | |||
@Test | |||
public void getOriginalFile_throws_NPE_when_file_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("file can't be null"); | |||
underTest.getOriginalFile(null); | |||
assertThatThrownBy(() -> underTest.getOriginalFile(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("file can't be null"); | |||
} | |||
@Test |
@@ -22,9 +22,7 @@ package org.sonar.ce.task.projectanalysis.filemove; | |||
import java.util.List; | |||
import java.util.stream.Collectors; | |||
import java.util.stream.IntStream; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static java.util.Arrays.asList; | |||
import static java.util.Collections.emptyList; | |||
@@ -32,8 +30,6 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
public class SourceSimilarityImplTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private SourceSimilarityImpl underTest = new SourceSimilarityImpl(); | |||
@@ -20,15 +20,14 @@ | |||
package org.sonar.ce.task.projectanalysis.formula; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.measure.Measure; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.ArgumentMatchers.anyString; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
@@ -49,43 +48,44 @@ public class AverageFormulaTest { | |||
CreateMeasureContext createMeasureContext = new DumbCreateMeasureContext( | |||
ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class)); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void fail_with_NPE_when_building_formula_without_output_metric() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Output metric key cannot be null"); | |||
Builder.newBuilder() | |||
.setOutputMetricKey(null) | |||
.setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY) | |||
.setByMetricKey(FUNCTIONS_KEY) | |||
.build(); | |||
assertThatThrownBy(() -> { | |||
Builder.newBuilder() | |||
.setOutputMetricKey(null) | |||
.setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY) | |||
.setByMetricKey(FUNCTIONS_KEY) | |||
.build(); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Output metric key cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_building_formula_without_main_metric() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Main metric Key cannot be null"); | |||
Builder.newBuilder() | |||
.setOutputMetricKey(FUNCTION_COMPLEXITY_KEY) | |||
.setMainMetricKey(null) | |||
.setByMetricKey(FUNCTIONS_KEY) | |||
.build(); | |||
assertThatThrownBy(() -> { | |||
Builder.newBuilder() | |||
.setOutputMetricKey(FUNCTION_COMPLEXITY_KEY) | |||
.setMainMetricKey(null) | |||
.setByMetricKey(FUNCTIONS_KEY) | |||
.build(); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Main metric Key cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_building_formula_without_by_metric() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("By metric Key cannot be null"); | |||
Builder.newBuilder() | |||
.setOutputMetricKey(FUNCTION_COMPLEXITY_KEY) | |||
.setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY) | |||
.setByMetricKey(null) | |||
.build(); | |||
assertThatThrownBy(() -> { | |||
Builder.newBuilder() | |||
.setOutputMetricKey(FUNCTION_COMPLEXITY_KEY) | |||
.setMainMetricKey(COMPLEXITY_IN_FUNCTIONS_KEY) | |||
.setByMetricKey(null) | |||
.build(); | |||
}) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("By metric Key cannot be null"); | |||
} | |||
@Test | |||
@@ -163,15 +163,16 @@ public class AverageFormulaTest { | |||
@Test | |||
public void fail_with_IAE_when_aggregate_from_component_and_context_with_not_numeric_measures() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Measure of type 'STRING' are not supported"); | |||
AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter(); | |||
addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L); | |||
when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create("data"))); | |||
counter.initialize(counterInitializationContext); | |||
BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext); | |||
assertThatThrownBy(() -> { | |||
AverageFormula.AverageCounter counter = BASIC_AVERAGE_FORMULA.createNewCounter(); | |||
addMeasure(COMPLEXITY_IN_FUNCTIONS_KEY, 10L); | |||
when(counterInitializationContext.getMeasure(FUNCTIONS_KEY)).thenReturn(Optional.of(Measure.newMeasureBuilder().create("data"))); | |||
counter.initialize(counterInitializationContext); | |||
BASIC_AVERAGE_FORMULA.createMeasure(counter, createMeasureContext); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Measure of type 'STRING' are not supported"); | |||
} | |||
@Test |
@@ -20,15 +20,14 @@ | |||
package org.sonar.ce.task.projectanalysis.formula; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.measure.Measure; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
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.when; | |||
import static org.sonar.api.measures.CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION_KEY; | |||
@@ -37,8 +36,6 @@ public class DistributionFormulaTest { | |||
private static final DistributionFormula BASIC_DISTRIBUTION_FORMULA = new DistributionFormula(FUNCTION_COMPLEXITY_DISTRIBUTION_KEY); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
CounterInitializationContext counterInitializationContext = mock(CounterInitializationContext.class); | |||
CreateMeasureContext projectCreateMeasureContext = new DumbCreateMeasureContext( | |||
@@ -53,10 +50,9 @@ public class DistributionFormulaTest { | |||
@Test | |||
public void fail_with_NPE_when_creating_counter_with_null_metric() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Metric key cannot be null"); | |||
new DistributionFormula(null); | |||
assertThatThrownBy(() -> new DistributionFormula(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Metric key cannot be null"); | |||
} | |||
@Test |
@@ -21,9 +21,7 @@ package org.sonar.ce.task.projectanalysis.formula; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.formula.SumFormula.IntSumFormula; | |||
@@ -32,6 +30,7 @@ import org.sonar.ce.task.projectanalysis.measure.Measure; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
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.when; | |||
import static org.sonar.api.measures.CoreMetrics.LINES_KEY; | |||
@@ -43,8 +42,6 @@ public class IntSumFormulaTest { | |||
private static final IntSumFormula INT_SUM_FORMULA_NULL_DEFAULT_INPUT_VALUE = createIntSumFormula(LINES_KEY, null); | |||
private static final IntSumFormula INT_SUM_FORMULA_DEFAULT_INPUT_VALUE_15 = createIntSumFormula(LINES_KEY, 15); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
CreateMeasureContext projectCreateMeasureContext = new DumbCreateMeasureContext( | |||
ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class)); | |||
@@ -58,10 +55,9 @@ public class IntSumFormulaTest { | |||
@Test | |||
public void fail_with_NPE_when_creating_formula_with_null_metric() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Metric key cannot be null"); | |||
createIntSumFormula(null); | |||
assertThatThrownBy(() -> createIntSumFormula(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Metric key cannot be null"); | |||
} | |||
@Test |
@@ -21,9 +21,7 @@ package org.sonar.ce.task.projectanalysis.formula; | |||
import java.util.Optional; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ReportComponent; | |||
import org.sonar.ce.task.projectanalysis.formula.counter.LongSumCounter; | |||
@@ -31,6 +29,7 @@ import org.sonar.ce.task.projectanalysis.measure.Measure; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
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.when; | |||
import static org.sonar.api.measures.CoreMetrics.LINES_KEY; | |||
@@ -42,8 +41,6 @@ public class LongSumFormulaTest { | |||
private static final SumFormula.LongSumFormula LONG_SUM_FORMULA_NULL_DEFAULT_INPUT_VALUE = createLongSumFormula(LINES_KEY, null); | |||
private static final SumFormula.LongSumFormula LONG_SUM_FORMULA_DEFAULT_INPUT_VALUE_15 = createLongSumFormula(LINES_KEY, 15L); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
CreateMeasureContext projectCreateMeasureContext = new DumbCreateMeasureContext( | |||
ReportComponent.builder(Component.Type.PROJECT, 1).build(), mock(Metric.class)); | |||
@@ -57,10 +54,9 @@ public class LongSumFormulaTest { | |||
@Test | |||
public void fail_with_NPE_when_creating_formula_with_null_metric() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Metric key cannot be null"); | |||
createLongSumFormula(null); | |||
assertThatThrownBy(() -> createLongSumFormula(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Metric key cannot be null"); | |||
} | |||
@Test |
@@ -23,7 +23,6 @@ import com.google.common.collect.ImmutableList; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.PathAwareCrawler; | |||
@@ -36,6 +35,7 @@ import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
import org.sonar.ce.task.projectanalysis.metric.MetricRepositoryRule; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.api.measures.CoreMetrics.LINES_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; | |||
import static org.sonar.api.measures.CoreMetrics.NEW_COVERAGE_KEY; | |||
@@ -46,7 +46,6 @@ import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builde | |||
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder; | |||
import static org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry.entryOf; | |||
import static org.sonar.ce.task.projectanalysis.measure.MeasureRepoEntry.toEntries; | |||
import static org.sonar.test.ExceptionCauseMatcher.hasType; | |||
public class ReportFormulaExecutorComponentVisitorTest { | |||
private static final int ROOT_REF = 1; | |||
@@ -69,8 +68,6 @@ public class ReportFormulaExecutorComponentVisitorTest { | |||
.build()) | |||
.build(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public TreeRootHolderRule treeRootHolder = new TreeRootHolderRule(); | |||
@Rule | |||
@@ -222,11 +219,13 @@ public class ReportFormulaExecutorComponentVisitorTest { | |||
treeRootHolder.setRoot(root); | |||
measureRepository.addRawMeasure(FILE_1_REF, NCLOC_KEY, newMeasureBuilder().create(2)); | |||
expectedException.expectCause(hasType(UnsupportedOperationException.class) | |||
.andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY))); | |||
// expectedException.expectCause( | |||
// hasType(UnsupportedOperationException.class) | |||
// .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY)) | |||
// ); | |||
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())) | |||
.visit(root); | |||
assertThatThrownBy(() -> new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())).visit(root)) | |||
.hasCause( new UnsupportedOperationException(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", FILE_1_REF, NCLOC_KEY))); | |||
} | |||
@Test | |||
@@ -235,11 +234,14 @@ public class ReportFormulaExecutorComponentVisitorTest { | |||
treeRootHolder.setRoot(root); | |||
measureRepository.addRawMeasure(ROOT_REF, NCLOC_KEY, newMeasureBuilder().create(10)); | |||
expectedException.expectCause(hasType(UnsupportedOperationException.class) | |||
.andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY))); | |||
// expectedException.expectCause(hasType(UnsupportedOperationException.class) | |||
// .andMessage(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY))); | |||
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())) | |||
.visit(root); | |||
assertThatThrownBy(() -> { | |||
new PathAwareCrawler<>(formulaExecutorComponentVisitor(new FakeFormula())) | |||
.visit(root); | |||
}) | |||
.hasCause(new UnsupportedOperationException(String.format("A measure can only be set once for Component (ref=%s), Metric (key=%s)", ROOT_REF, NCLOC_KEY))); | |||
} | |||
private FormulaExecutorComponentVisitor formulaExecutorComponentVisitor(Formula formula) { |
@@ -24,7 +24,6 @@ import java.util.Map; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.ExternalResource; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.formula.CounterInitializationContext; | |||
@@ -33,6 +32,7 @@ import org.sonar.ce.task.projectanalysis.measure.Measure; | |||
import static com.google.common.base.Preconditions.checkNotNull; | |||
import static com.google.common.base.Preconditions.checkState; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.formula.coverage.CoverageUtils.getLongMeasureValue; | |||
import static org.sonar.ce.task.projectanalysis.formula.coverage.CoverageUtils.getMeasureVariations; | |||
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder; | |||
@@ -44,8 +44,6 @@ public class CoverageUtilsTest { | |||
@Rule | |||
public CounterInitializationContextRule fileAggregateContext = new CounterInitializationContextRule(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void verify_calculate_coverage() { | |||
@@ -80,12 +78,12 @@ public class CoverageUtilsTest { | |||
@Test | |||
public void getLongMeasureValue_throws_ISE_if_measure_is_DOUBLE() { | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("value can not be converted to long because current value type is a DOUBLE"); | |||
fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().create(152d, 1)); | |||
getLongMeasureValue(fileAggregateContext, SOME_METRIC_KEY); | |||
assertThatThrownBy(() -> { | |||
fileAggregateContext.put(SOME_METRIC_KEY, newMeasureBuilder().create(152d, 1)); | |||
getLongMeasureValue(fileAggregateContext, SOME_METRIC_KEY); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("value can not be converted to long because current value type is a DOUBLE"); | |||
} | |||
@Test |
@@ -33,7 +33,6 @@ import java.util.stream.IntStream; | |||
import javax.annotation.Nullable; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.config.Configuration; | |||
import org.sonar.api.config.internal.MapSettings; | |||
@@ -66,8 +65,6 @@ public class ComponentIssuesLoaderTest { | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private DbClient dbClient = db.getDbClient(); | |||
private System2 system2 = mock(System2.class); |
@@ -22,17 +22,15 @@ package org.sonar.ce.task.projectanalysis.issue; | |||
import java.util.Arrays; | |||
import java.util.Collections; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.core.issue.DefaultIssue; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder; | |||
public class ComponentIssuesRepositoryImplTest { | |||
@org.junit.Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
static final Component FILE_1 = builder(Component.Type.FILE, 1).build(); | |||
static final Component FILE_2 = builder(Component.Type.FILE, 2).build(); | |||
@@ -62,34 +60,34 @@ public class ComponentIssuesRepositoryImplTest { | |||
@Test | |||
public void fail_with_NPE_when_setting_issues_with_null_component() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("component cannot be null"); | |||
sut.setIssues(null, Arrays.asList(DUMB_ISSUE)); | |||
assertThatThrownBy(() -> sut.setIssues(null, Arrays.asList(DUMB_ISSUE))) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("component cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_NPE_when_setting_issues_with_null_issues() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("issues cannot be null"); | |||
sut.setIssues(FILE_1, null); | |||
assertThatThrownBy(() -> sut.setIssues(FILE_1, null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("issues cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_IAE_when_getting_issues_on_different_component() { | |||
thrown.expect(IllegalArgumentException.class); | |||
thrown.expectMessage("Only issues from component '1' are available, but wanted component is '2'."); | |||
sut.setIssues(FILE_1, Arrays.asList(DUMB_ISSUE)); | |||
sut.getIssues(FILE_2); | |||
assertThatThrownBy(() -> { | |||
sut.setIssues(FILE_1, Arrays.asList(DUMB_ISSUE)); | |||
sut.getIssues(FILE_2); | |||
}) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Only issues from component '1' are available, but wanted component is '2'."); | |||
} | |||
@Test | |||
public void fail_with_ISE_when_getting_issues_but_issues_are_null() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Issues have not been initialized"); | |||
sut.getIssues(FILE_1); | |||
assertThatThrownBy(() -> { | |||
sut.getIssues(FILE_1); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Issues have not been initialized"); | |||
} | |||
} |
@@ -20,17 +20,14 @@ | |||
package org.sonar.ce.task.projectanalysis.issue; | |||
import java.util.Set; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import static com.google.common.collect.Sets.newHashSet; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class ComponentsWithUnprocessedIssuesTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
ComponentsWithUnprocessedIssues sut = new ComponentsWithUnprocessedIssues(); | |||
@@ -55,19 +52,19 @@ public class ComponentsWithUnprocessedIssuesTest { | |||
@Test | |||
public void fail_with_NPE_when_setting_null_uuids() { | |||
thrown.expect(NullPointerException.class); | |||
thrown.expectMessage("Uuids cannot be null"); | |||
sut.setUuids(null); | |||
assertThatThrownBy(() -> sut.setUuids(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("Uuids cannot be null"); | |||
} | |||
@Test | |||
public void fail_with_ISE_when_setting_uuids_twice() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Uuids have already been initialized"); | |||
sut.setUuids(newHashSet("ABCD")); | |||
sut.setUuids(newHashSet("EFGH")); | |||
assertThatThrownBy(() -> { | |||
sut.setUuids(newHashSet("ABCD")); | |||
sut.setUuids(newHashSet("EFGH")); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Uuids have already been initialized"); | |||
} | |||
@Test | |||
@@ -80,17 +77,15 @@ public class ComponentsWithUnprocessedIssuesTest { | |||
@Test | |||
public void fail_with_ISE_when_removing_uuid_and_not_initialized() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Uuids have not been initialized yet"); | |||
sut.remove("ABCD"); | |||
assertThatThrownBy(() -> sut.remove("ABCD")) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Uuids have not been initialized yet"); | |||
} | |||
@Test | |||
public void fail_with_ISE_when_getting_uuid_and_not_initialized() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Uuids have not been initialized yet"); | |||
sut.getUuids(); | |||
assertThatThrownBy(() -> sut.getUuids()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Uuids have not been initialized yet"); | |||
} | |||
} |
@@ -28,6 +28,7 @@ import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.db.rule.RuleTesting; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class DebtCalculatorTest { | |||
@@ -92,13 +93,14 @@ public class DebtCalculatorTest { | |||
assertThat(underTest.calculate(issue).toMinutes()).isEqualTo(2); | |||
} | |||
@Test(expected = IllegalArgumentException.class) | |||
@Test | |||
public void effort_to_fix_must_not_be_set_with_constant_function() { | |||
int constant = 2; | |||
issue.setGap(3.0); | |||
rule.setFunction(new DefaultDebtRemediationFunction(DebtRemediationFunction.Type.CONSTANT_ISSUE, null, constant + "min")); | |||
underTest.calculate(issue); | |||
assertThatThrownBy(() -> underTest.calculate(issue)) | |||
.isInstanceOf(IllegalArgumentException.class); | |||
} | |||
@Test |
@@ -32,7 +32,6 @@ import java.util.stream.Stream; | |||
import org.apache.commons.lang.ArrayUtils; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.ce.task.projectanalysis.analysis.Analysis; | |||
@@ -54,6 +53,7 @@ import org.sonar.db.protobuf.DbIssues.Location; | |||
import org.sonar.db.protobuf.DbIssues.Locations.Builder; | |||
import org.sonar.server.issue.IssueFieldsSetter; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.ArgumentMatchers.same; | |||
@@ -71,8 +71,6 @@ public class IssueCreationDateCalculatorTest { | |||
@org.junit.Rule | |||
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); | |||
@org.junit.Rule | |||
public ExpectedException exception = ExpectedException.none(); | |||
private ScmInfoRepository scmInfoRepository = mock(ScmInfoRepository.class); | |||
private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); | |||
@@ -192,9 +190,9 @@ public class IssueCreationDateCalculatorTest { | |||
when(ruleRepository.findByKey(ruleKey)).thenReturn(Optional.empty()); | |||
makeIssueNew(); | |||
exception.expect(IllegalStateException.class); | |||
exception.expectMessage("The rule with key 'reop:rule' raised an issue, but no rule with that key was found"); | |||
run(); | |||
assertThatThrownBy(this::run) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("The rule with key 'reop:rule' raised an issue, but no rule with that key was found"); | |||
} | |||
@Test |
@@ -23,7 +23,6 @@ import java.util.Date; | |||
import java.util.Optional; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.mockito.ArgumentCaptor; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
@@ -34,6 +33,7 @@ import org.sonar.core.issue.IssueChangeContext; | |||
import org.sonar.server.issue.IssueFieldsSetter; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
@@ -51,8 +51,6 @@ public class MovedIssueVisitorTest { | |||
.setUuid(FILE_UUID) | |||
.build(); | |||
@org.junit.Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@org.junit.Rule | |||
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); | |||
@@ -88,11 +86,10 @@ public class MovedIssueVisitorTest { | |||
DefaultIssue issue = mockIssue("other component uuid"); | |||
when(issue.toString()).thenReturn("[bad issue, bad!]"); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Issue [bad issue, bad!] for component ReportComponent{ref=1, key='key_1', type=FILE} " + | |||
"has a different component key but no original file exist in MovedFilesRepository"); | |||
underTest.onIssue(FILE, issue); | |||
assertThatThrownBy(() -> underTest.onIssue(FILE, issue)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Issue [bad issue, bad!] for component ReportComponent{ref=1, key='key_1', type=FILE} " + | |||
"has a different component key but no original file exist in MovedFilesRepository"); | |||
} | |||
@Test | |||
@@ -102,11 +99,10 @@ public class MovedIssueVisitorTest { | |||
when(movedFilesRepository.getOriginalFile(FILE)) | |||
.thenReturn(Optional.of(new MovedFilesRepository.OriginalFile("original uuid", "original key"))); | |||
expectedException.expect(IllegalStateException.class); | |||
expectedException.expectMessage("Issue [bad issue, bad!] doesn't belong to file original uuid registered as original " + | |||
"file of current file ReportComponent{ref=1, key='key_1', type=FILE}"); | |||
underTest.onIssue(FILE, issue); | |||
assertThatThrownBy(() -> underTest.onIssue(FILE, issue)) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Issue [bad issue, bad!] doesn't belong to file original uuid registered as original " + | |||
"file of current file ReportComponent{ref=1, key='key_1', type=FILE}"); | |||
} | |||
@Test |
@@ -20,21 +20,18 @@ | |||
package org.sonar.ce.task.projectanalysis.issue; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class NewAdHocRuleTest { | |||
@org.junit.Rule | |||
public ExpectedException exception = ExpectedException.none(); | |||
@Test | |||
public void fail_if_engine_id_is_not_set() { | |||
exception.expect(IllegalArgumentException.class); | |||
exception.expectMessage("'engine id' not expected to be null for an ad hoc rule"); | |||
new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().build()); | |||
assertThatThrownBy(() -> new NewAdHocRule(ScannerReport.ExternalIssue.newBuilder().build())) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("'engine id' not expected to be null for an ad hoc rule"); | |||
} | |||
@Test |
@@ -22,14 +22,13 @@ package org.sonar.ce.task.projectanalysis.issue; | |||
import com.google.common.collect.ImmutableList; | |||
import com.google.common.collect.ImmutableSet; | |||
import java.util.Optional; | |||
import org.assertj.core.api.ThrowableAssert.ThrowingCallable; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.RuleStatus; | |||
import org.sonar.api.rules.RuleType; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule; | |||
import org.sonar.core.util.SequenceUuidFactory; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbSession; | |||
@@ -42,9 +41,9 @@ import org.sonar.scanner.protocol.output.ScannerReport; | |||
import org.sonar.server.rule.index.RuleIndexer; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.ArgumentMatchers.any; | |||
import static org.mockito.ArgumentMatchers.anyBoolean; | |||
import static org.mockito.ArgumentMatchers.eq; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.reset; | |||
import static org.mockito.Mockito.verify; | |||
@@ -60,8 +59,6 @@ public class RuleRepositoryImplTest { | |||
private static final RuleKey AC_RULE_KEY = RuleKey.of("a", "c"); | |||
private static final String AC_RULE_UUID = "uuid-684"; | |||
@org.junit.Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@org.junit.Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
@@ -139,9 +136,7 @@ public class RuleRepositoryImplTest { | |||
@Test | |||
public void getByKey_throws_NPE_if_key_argument_is_null() { | |||
expectNullRuleKeyNPE(); | |||
underTest.getByKey(null); | |||
expectNullRuleKeyNPE(() -> underTest.getByKey(null)); | |||
} | |||
@Test | |||
@@ -169,28 +164,23 @@ public class RuleRepositoryImplTest { | |||
@Test | |||
public void getByKey_throws_IAE_if_rules_does_not_exist_in_DB() { | |||
expectIAERuleNotFound(AC_RULE_KEY); | |||
underTest.getByKey(AC_RULE_KEY); | |||
expectIAERuleNotFound(() -> underTest.getByKey(AC_RULE_KEY), AC_RULE_KEY); | |||
} | |||
@Test | |||
public void getByKey_throws_IAE_if_argument_is_deprecated_key_in_DB_of_non_existing_rule() { | |||
expectIAERuleNotFound(DEPRECATED_KEY_OF_NON_EXITING_RULE); | |||
underTest.getByKey(DEPRECATED_KEY_OF_NON_EXITING_RULE); | |||
expectIAERuleNotFound(() -> underTest.getByKey(DEPRECATED_KEY_OF_NON_EXITING_RULE), DEPRECATED_KEY_OF_NON_EXITING_RULE); | |||
} | |||
private void expectIAERuleNotFound(RuleKey ruleKey) { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Can not find rule for key " + ruleKey.toString() + ". This rule does not exist in DB"); | |||
private void expectIAERuleNotFound(ThrowingCallable callback, RuleKey ruleKey) { | |||
assertThatThrownBy(callback) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Can not find rule for key " + ruleKey.toString() + ". This rule does not exist in DB"); | |||
} | |||
@Test | |||
public void findByKey_throws_NPE_if_key_argument_is_null() { | |||
expectNullRuleKeyNPE(); | |||
underTest.findByKey(null); | |||
expectNullRuleKeyNPE(() -> underTest.findByKey(null)); | |||
} | |||
@Test | |||
@@ -239,10 +229,9 @@ public class RuleRepositoryImplTest { | |||
@Test | |||
public void getByUuid_throws_IAE_if_rules_does_not_exist_in_DB() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Can not find rule for uuid " + AC_RULE_UUID + ". This rule does not exist in DB"); | |||
underTest.getByUuid(AC_RULE_UUID); | |||
assertThatThrownBy(() -> underTest.getByUuid(AC_RULE_UUID)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Can not find rule for uuid " + AC_RULE_UUID + ". This rule does not exist in DB"); | |||
} | |||
@Test | |||
@@ -293,9 +282,10 @@ public class RuleRepositoryImplTest { | |||
verify(ruleIndexer).commitAndIndex(db.getSession(), ruleDefinitionDto.get().getUuid()); | |||
} | |||
private void expectNullRuleKeyNPE() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expectMessage("RuleKey can not be null"); | |||
private void expectNullRuleKeyNPE(ThrowingCallable callback) { | |||
assertThatThrownBy(callback) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("RuleKey can not be null"); | |||
} | |||
private void verifyNoMethodCallTriggersCallToDB() { |
@@ -22,7 +22,6 @@ package org.sonar.ce.task.projectanalysis.issue.commonrule; | |||
import com.google.common.collect.ImmutableMap; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.measures.CoreMetrics; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.api.rule.Severity; | |||
@@ -39,6 +38,7 @@ import org.sonar.core.issue.DefaultIssue; | |||
import org.sonar.server.rule.CommonRuleKeys; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.component.ReportComponent.DUMB_PROJECT; | |||
public class CommentDensityRuleTest { | |||
@@ -56,8 +56,6 @@ public class CommentDensityRuleTest { | |||
.setFileAttributes(new FileAttributes(true, PLUGIN_KEY, 1)) | |||
.build(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Rule | |||
public ActiveRulesHolderRule activeRuleHolder = new ActiveRulesHolderRule(); | |||
@@ -127,12 +125,12 @@ public class CommentDensityRuleTest { | |||
*/ | |||
@Test | |||
public void fail_if_min_density_is_100() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Minimum density of rule [common-java:InsufficientCommentDensity] is incorrect. Got [100] but must be strictly less than 100."); | |||
prepareForIssue("100", FILE, 0.0, 0, 1); | |||
underTest.processFile(FILE, PLUGIN_KEY); | |||
assertThatThrownBy(() -> { | |||
prepareForIssue("100", FILE, 0.0, 0, 1); | |||
underTest.processFile(FILE, PLUGIN_KEY); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Minimum density of rule [common-java:InsufficientCommentDensity] is incorrect. Got [100] but must be strictly less than 100."); | |||
} | |||
private void prepareForIssue(String minDensity, ReportComponent file, double commentLineDensity, int commentLines, int ncloc) { |
@@ -20,22 +20,19 @@ | |||
package org.sonar.ce.task.projectanalysis.issue.commonrule; | |||
import com.google.common.collect.ImmutableMap; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.rule.Severity; | |||
import org.sonar.ce.task.projectanalysis.qualityprofile.ActiveRule; | |||
import org.sonar.db.rule.RuleTesting; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class CommonRuleTest { | |||
private static final String PLUGIN_KEY = "java"; | |||
private static final String QP_KEY = "qp1"; | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@Test | |||
public void test_getMinDensityParam() { | |||
@@ -47,28 +44,31 @@ public class CommonRuleTest { | |||
@Test | |||
public void getMinDensityParam_fails_if_param_value_is_absent() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Required parameter [minDensity] is missing on rule [xoo:x1]"); | |||
ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of(), 1_000L, PLUGIN_KEY, QP_KEY); | |||
CommonRule.getMinDensityParam(activeRule, "minDensity"); | |||
assertThatThrownBy(() -> { | |||
ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of(), 1_000L, PLUGIN_KEY, QP_KEY); | |||
CommonRule.getMinDensityParam(activeRule, "minDensity"); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Required parameter [minDensity] is missing on rule [xoo:x1]"); | |||
} | |||
@Test | |||
public void getMinDensityParam_fails_if_param_value_is_negative() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Minimum density of rule [xoo:x1] is incorrect. Got [-30.5] but must be between 0 and 100."); | |||
ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "-30.5"), 1_000L, PLUGIN_KEY, QP_KEY); | |||
CommonRule.getMinDensityParam(activeRule, "minDensity"); | |||
assertThatThrownBy(() -> { | |||
ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "-30.5"), 1_000L, PLUGIN_KEY, QP_KEY); | |||
CommonRule.getMinDensityParam(activeRule, "minDensity"); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Minimum density of rule [xoo:x1] is incorrect. Got [-30.5] but must be between 0 and 100."); | |||
} | |||
@Test | |||
public void getMinDensityParam_fails_if_param_value_is_greater_than_100() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Minimum density of rule [xoo:x1] is incorrect. Got [305] but must be between 0 and 100."); | |||
ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "305"), 1_000L, PLUGIN_KEY, QP_KEY); | |||
CommonRule.getMinDensityParam(activeRule, "minDensity"); | |||
assertThatThrownBy(() -> { | |||
ActiveRule activeRule = new ActiveRule(RuleTesting.XOO_X1, Severity.MAJOR, ImmutableMap.of("minDensity", "305"), 1_000L, PLUGIN_KEY, QP_KEY); | |||
CommonRule.getMinDensityParam(activeRule, "minDensity"); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Minimum density of rule [xoo:x1] is incorrect. Got [305] but must be between 0 and 100."); | |||
} | |||
} |
@@ -25,9 +25,8 @@ import java.util.Collections; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.config.internal.MapSettings; | |||
import org.sonar.api.config.internal.Settings; | |||
import org.sonar.api.rule.RuleKey; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.component.ConfigurationRepository; | |||
@@ -36,6 +35,7 @@ import org.sonar.core.issue.DefaultIssue; | |||
import static java.util.Arrays.asList; | |||
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.when; | |||
import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE; | |||
@@ -43,8 +43,6 @@ import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builde | |||
public class IssueFilterTest { | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
static final RuleKey XOO_X1 = RuleKey.of("xoo", "x1"); | |||
static final RuleKey XOO_X2 = RuleKey.of("xoo", "x2"); | |||
@@ -166,18 +164,16 @@ public class IssueFilterTest { | |||
@Test | |||
public void fail_when_only_rule_key_parameter() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("File path pattern cannot be empty. Please check 'sonar.issue.ignore.multicriteria' settings"); | |||
newIssueFilter(newSettings(asList("xoo:x1", ""), Collections.emptyList())); | |||
assertThatThrownBy(() -> newIssueFilter(newSettings(asList("xoo:x1", ""), Collections.emptyList()))) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("File path pattern cannot be empty. Please check 'sonar.issue.ignore.multicriteria' settings"); | |||
} | |||
@Test | |||
public void fail_when_only_path_parameter() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("Rule key pattern cannot be empty. Please check 'sonar.issue.enforce.multicriteria' settings"); | |||
newIssueFilter(newSettings(Collections.emptyList(), asList("", "**"))); | |||
assertThatThrownBy(() -> newIssueFilter(newSettings(Collections.emptyList(), asList("", "**")))) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("Rule key pattern cannot be empty. Please check 'sonar.issue.enforce.multicriteria' settings"); | |||
} | |||
private IssueFilter newIssueFilter(MapSettings settings) { |
@@ -24,6 +24,7 @@ import org.junit.Test; | |||
import org.sonar.api.resources.Language; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class LanguageRepositoryImplTest { | |||
@@ -31,9 +32,10 @@ public class LanguageRepositoryImplTest { | |||
private static final String SOME_LANGUAGE_KEY = "SoMe language_Key"; | |||
private static final Language SOME_LANGUAGE = createLanguage(SOME_LANGUAGE_KEY, "_name"); | |||
@Test(expected = IllegalArgumentException.class) | |||
@Test | |||
public void constructor_fails_is_language_have_the_same_key() { | |||
new LanguageRepositoryImpl(createLanguage(SOME_LANGUAGE_KEY, " 1"), createLanguage(SOME_LANGUAGE_KEY, " 2")); | |||
assertThatThrownBy(() -> new LanguageRepositoryImpl(createLanguage(SOME_LANGUAGE_KEY, " 1"), createLanguage(SOME_LANGUAGE_KEY, " 2"))) | |||
.isInstanceOf(IllegalArgumentException.class); | |||
} | |||
@Test |
@@ -34,6 +34,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.Measure.LongValue; | |||
import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class BatchMeasureToMeasureTest { | |||
@@ -54,14 +55,16 @@ public class BatchMeasureToMeasureTest { | |||
assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isNotPresent(); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasure_throws_NPE_if_metric_argument_is_null() { | |||
underTest.toMeasure(EMPTY_BATCH_MEASURE, null); | |||
assertThatThrownBy(() -> underTest.toMeasure(EMPTY_BATCH_MEASURE, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasure_throws_NPE_if_both_arguments_are_null() { | |||
underTest.toMeasure(null, null); | |||
assertThatThrownBy(() -> underTest.toMeasure(null, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -24,9 +24,7 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Optional; | |||
import org.assertj.core.data.Offset; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.measure.Measure.Level; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
@@ -34,6 +32,7 @@ import org.sonar.ce.task.projectanalysis.metric.MetricImpl; | |||
import org.sonar.db.measure.LiveMeasureDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class LiveMeasureDtoToMeasureTest { | |||
@@ -48,8 +47,6 @@ public class LiveMeasureDtoToMeasureTest { | |||
private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!"; | |||
private static final LiveMeasureDto EMPTY_MEASURE_DTO = new LiveMeasureDto(); | |||
@Rule | |||
public final ExpectedException expectedException = ExpectedException.none(); | |||
private LiveMeasureDtoToMeasure underTest = new LiveMeasureDtoToMeasure(); | |||
@@ -58,14 +55,16 @@ public class LiveMeasureDtoToMeasureTest { | |||
assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isNotPresent(); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasure_throws_NPE_if_metric_argument_is_null() { | |||
underTest.toMeasure(EMPTY_MEASURE_DTO, null); | |||
assertThatThrownBy(() -> underTest.toMeasure(EMPTY_MEASURE_DTO, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasure_throws_NPE_if_both_arguments_are_null() { | |||
underTest.toMeasure(null, null); | |||
assertThatThrownBy(() -> underTest.toMeasure(null, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test |
@@ -28,7 +28,6 @@ import java.util.Optional; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; | |||
@@ -43,6 +42,7 @@ import org.sonar.db.DbTester; | |||
import static java.lang.String.format; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.junit.Assert.fail; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
@@ -52,8 +52,6 @@ import static org.mockito.Mockito.when; | |||
public class MapBasedRawMeasureRepositoryTest { | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
private static final String FILE_COMPONENT_KEY = "file cpt key"; | |||
private static final ReportComponent FILE_COMPONENT = ReportComponent.builder(Component.Type.FILE, 1) | |||
@@ -92,45 +90,53 @@ public class MapBasedRawMeasureRepositoryTest { | |||
when(metricRepository.getByKey(METRIC_KEY_2)).thenReturn(metric2); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void add_throws_NPE_if_Component_argument_is_null() { | |||
underTest.add(null, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.add(null, metric1, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void add_throws_NPE_if_Component_metric_is_null() { | |||
underTest.add(FILE_COMPONENT, null, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.add(FILE_COMPONENT, null, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void add_throws_NPE_if_Component_measure_is_null() { | |||
underTest.add(FILE_COMPONENT, metric1, null); | |||
assertThatThrownBy(() -> underTest.add(FILE_COMPONENT, metric1, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = UnsupportedOperationException.class) | |||
@Test | |||
public void add_throws_UOE_if_measure_already_exists() { | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE)) | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void update_throws_NPE_if_Component_argument_is_null() { | |||
underTest.update(null, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.update(null, metric1, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void update_throws_NPE_if_Component_metric_is_null() { | |||
underTest.update(FILE_COMPONENT, null, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, null, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void update_throws_NPE_if_Component_measure_is_null() { | |||
underTest.update(FILE_COMPONENT, metric1, null); | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, metric1, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = UnsupportedOperationException.class) | |||
@Test | |||
public void update_throws_UOE_if_measure_does_not_exists() { | |||
underTest.update(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, metric1, SOME_MEASURE)) | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
private static final List<Measure> MEASURES = ImmutableList.of( |
@@ -21,18 +21,15 @@ package org.sonar.ce.task.projectanalysis.measure; | |||
import com.google.common.collect.ImmutableList; | |||
import java.util.Collections; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.sonar.ce.task.projectanalysis.api.measurecomputer.MeasureComputerWrapper; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.mockito.Mockito.mock; | |||
public class MeasureComputersHolderImplTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
private MeasureComputersHolderImpl underTest = new MeasureComputersHolderImpl(); | |||
@@ -46,10 +43,9 @@ public class MeasureComputersHolderImplTest { | |||
@Test | |||
public void get_measure_computers_throws_ISE_if_not_initialized() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Measure computers have not been initialized yet"); | |||
underTest.getMeasureComputers(); | |||
assertThatThrownBy(() -> underTest.getMeasureComputers()) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Measure computers have not been initialized yet"); | |||
} | |||
@Test | |||
@@ -61,12 +57,13 @@ public class MeasureComputersHolderImplTest { | |||
@Test | |||
public void set_measure_computers_throws_ISE_if_already_initialized() { | |||
thrown.expect(IllegalStateException.class); | |||
thrown.expectMessage("Measure computers have already been initialized"); | |||
MeasureComputerWrapper measureComputer = mock(MeasureComputerWrapper.class); | |||
underTest.setMeasureComputers(Collections.singletonList(measureComputer)); | |||
underTest.setMeasureComputers(Collections.singletonList(measureComputer)); | |||
assertThatThrownBy(() -> { | |||
MeasureComputerWrapper measureComputer = mock(MeasureComputerWrapper.class); | |||
underTest.setMeasureComputers(Collections.singletonList(measureComputer)); | |||
underTest.setMeasureComputers(Collections.singletonList(measureComputer)); | |||
}) | |||
.isInstanceOf(IllegalStateException.class) | |||
.hasMessage("Measure computers have already been initialized"); | |||
} | |||
} |
@@ -24,9 +24,7 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.Optional; | |||
import org.assertj.core.data.Offset; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.measure.Measure.Level; | |||
import org.sonar.ce.task.projectanalysis.metric.Metric; | |||
@@ -34,6 +32,7 @@ import org.sonar.ce.task.projectanalysis.metric.MetricImpl; | |||
import org.sonar.db.measure.MeasureDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class MeasureDtoToMeasureTest { | |||
@@ -48,8 +47,6 @@ public class MeasureDtoToMeasureTest { | |||
private static final String SOME_ALERT_TEXT = "some alert text_be_careFul!"; | |||
private static final MeasureDto EMPTY_MEASURE_DTO = new MeasureDto(); | |||
@Rule | |||
public final ExpectedException expectedException = ExpectedException.none(); | |||
private MeasureDtoToMeasure underTest = new MeasureDtoToMeasure(); | |||
@@ -58,14 +55,16 @@ public class MeasureDtoToMeasureTest { | |||
assertThat(underTest.toMeasure(null, SOME_INT_METRIC)).isNotPresent(); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasure_throws_NPE_if_metric_argument_is_null() { | |||
underTest.toMeasure(EMPTY_MEASURE_DTO, null); | |||
assertThatThrownBy(() -> underTest.toMeasure(EMPTY_MEASURE_DTO, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasure_throws_NPE_if_both_arguments_are_null() { | |||
underTest.toMeasure(null, null); | |||
assertThatThrownBy(() -> underTest.toMeasure(null, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
@@ -137,14 +136,16 @@ public class MeasureDtoToMeasureTest { | |||
assertThat(measure.get().getQualityGateStatus().getText()).isEqualTo(SOME_ALERT_TEXT); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
public void toMeasure_for_LEVEL_Metric_ignores_data() { | |||
MeasureDto measureDto = new MeasureDto().setAlertStatus(Level.ERROR.name()).setData(SOME_DATA); | |||
Optional<Measure> measure = underTest.toMeasure(measureDto, SOME_LEVEL_METRIC); | |||
assertThat(measure).isPresent(); | |||
measure.get().getStringValue(); | |||
assertThatThrownBy(() ->measure.get().getStringValue()) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test |
@@ -31,7 +31,6 @@ import javax.annotation.Nullable; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; | |||
@@ -55,6 +54,7 @@ import org.sonar.scanner.protocol.output.ScannerReport.Measure.StringValue; | |||
import static com.google.common.collect.FluentIterable.from; | |||
import static java.lang.String.format; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.junit.Assert.fail; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.verifyNoMoreInteractions; | |||
@@ -65,8 +65,6 @@ import static org.sonar.db.component.ComponentTesting.newFileDto; | |||
@RunWith(DataProviderRunner.class) | |||
public class MeasureRepositoryImplTest { | |||
@Rule | |||
public final ExpectedException expectedException = ExpectedException.none(); | |||
@Rule | |||
public DbTester dbTester = DbTester.create(System2.INSTANCE); | |||
@@ -167,52 +165,52 @@ public class MeasureRepositoryImplTest { | |||
@Test | |||
public void add_throws_NPE_if_Component_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
underTest.add(null, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.add(null, metric1, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void add_throws_NPE_if_Component_metric_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
underTest.add(FILE_COMPONENT, null, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.add(FILE_COMPONENT, null, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void add_throws_NPE_if_Component_measure_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
underTest.add(FILE_COMPONENT, metric1, null); | |||
assertThatThrownBy(() -> underTest.add(FILE_COMPONENT, metric1, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void add_throws_UOE_if_measure_already_exists() { | |||
expectedException.expect(UnsupportedOperationException.class); | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> { | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
}) | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
@Test | |||
public void update_throws_NPE_if_Component_argument_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
underTest.update(null, metric1, SOME_MEASURE); | |||
} | |||
@Test | |||
public void update_throws_NPE_if_Component_metric_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
underTest.update(FILE_COMPONENT, null, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, null, SOME_MEASURE)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void update_throws_NPE_if_Component_measure_is_null() { | |||
expectedException.expect(NullPointerException.class); | |||
expectedException.expect(NullPointerException.class); | |||
underTest.update(FILE_COMPONENT, metric1, null); | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, metric1, null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
public void update_throws_UOE_if_measure_does_not_exists() { | |||
expectedException.expect(UnsupportedOperationException.class); | |||
underTest.update(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
assertThatThrownBy(() -> underTest.update(FILE_COMPONENT, metric1, SOME_MEASURE)) | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
private static final List<Measure> MEASURES = ImmutableList.of( |
@@ -24,14 +24,13 @@ import com.tngtech.java.junit.dataprovider.DataProvider; | |||
import com.tngtech.java.junit.dataprovider.DataProviderRunner; | |||
import com.tngtech.java.junit.dataprovider.UseDataProvider; | |||
import java.util.List; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.runner.RunWith; | |||
import org.sonar.ce.task.projectanalysis.measure.Measure.ValueType; | |||
import org.sonar.ce.task.projectanalysis.util.WrapInSingleElementArray; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.ce.task.projectanalysis.measure.Measure.newMeasureBuilder; | |||
@RunWith(DataProviderRunner.class) | |||
@@ -49,8 +48,6 @@ public class MeasureTest { | |||
private static final List<Measure> MEASURES = ImmutableList.of( | |||
INT_MEASURE, LONG_MEASURE, DOUBLE_MEASURE, STRING_MEASURE, TRUE_MEASURE, FALSE_MEASURE, NO_VALUE_MEASURE, LEVEL_MEASURE); | |||
@Rule | |||
public final ExpectedException expectedException = ExpectedException.none(); | |||
@DataProvider | |||
public static Object[][] all_but_INT_MEASURE() { | |||
@@ -94,9 +91,10 @@ public class MeasureTest { | |||
.toArray(Object[][]::new); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void create_from_String_throws_NPE_if_arg_is_null() { | |||
newMeasureBuilder().create((String) null); | |||
assertThatThrownBy(() -> newMeasureBuilder().create((String) null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test | |||
@@ -125,10 +123,11 @@ public class MeasureTest { | |||
assertThat(STRING_MEASURE.getValueType()).isEqualTo(ValueType.STRING); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all_but_INT_MEASURE") | |||
public void getIntValue_throws_ISE_for_all_value_types_except_INT(Measure measure) { | |||
measure.getIntValue(); | |||
assertThatThrownBy(measure::getIntValue) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -136,10 +135,11 @@ public class MeasureTest { | |||
assertThat(INT_MEASURE.getIntValue()).isEqualTo(1); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all_but_LONG_MEASURE") | |||
public void getLongValue_throws_ISE_for_all_value_types_except_LONG(Measure measure) { | |||
measure.getLongValue(); | |||
assertThatThrownBy(measure::getLongValue) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -147,10 +147,11 @@ public class MeasureTest { | |||
assertThat(LONG_MEASURE.getLongValue()).isEqualTo(1); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all_but_DOUBLE_MEASURE") | |||
public void getDoubleValue_throws_ISE_for_all_value_types_except_DOUBLE(Measure measure) { | |||
measure.getDoubleValue(); | |||
assertThatThrownBy(measure::getDoubleValue) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -158,10 +159,11 @@ public class MeasureTest { | |||
assertThat(DOUBLE_MEASURE.getDoubleValue()).isEqualTo(1d); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all_but_BOOLEAN_MEASURE") | |||
public void getBooleanValue_throws_ISE_for_all_value_types_except_BOOLEAN(Measure measure) { | |||
measure.getBooleanValue(); | |||
assertThatThrownBy(measure::getBooleanValue) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -170,16 +172,18 @@ public class MeasureTest { | |||
assertThat(FALSE_MEASURE.getBooleanValue()).isFalse(); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all_but_STRING_MEASURE") | |||
public void getStringValue_throws_ISE_for_all_value_types_except_STRING(Measure measure) { | |||
measure.getStringValue(); | |||
assertThatThrownBy(measure::getStringValue) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all_but_LEVEL_MEASURE") | |||
public void getLevelValue_throws_ISE_for_all_value_types_except_LEVEL(Measure measure) { | |||
measure.getLevelValue(); | |||
assertThatThrownBy(measure::getLevelValue) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -204,10 +208,11 @@ public class MeasureTest { | |||
assertThat(measure.hasQualityGateStatus()).isFalse(); | |||
} | |||
@Test(expected = IllegalStateException.class) | |||
@Test | |||
@UseDataProvider("all") | |||
public void getAlertStatus_throws_ISE_for_all_value_types_when_not_set(Measure measure) { | |||
measure.getQualityGateStatus(); | |||
assertThatThrownBy(measure::getQualityGateStatus) | |||
.isInstanceOf(IllegalStateException.class); | |||
} | |||
@Test | |||
@@ -223,26 +228,33 @@ public class MeasureTest { | |||
assertThat(newMeasureBuilder().setQualityGateStatus(someStatus).create(Measure.Level.OK).getQualityGateStatus()).isEqualTo(someStatus); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void newMeasureBuilder_setQualityGateStatus_throws_NPE_if_arg_is_null() { | |||
newMeasureBuilder().setQualityGateStatus(null); | |||
assertThatThrownBy(() -> newMeasureBuilder().setQualityGateStatus(null)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void updateMeasureBuilder_setQualityGateStatus_throws_NPE_if_arg_is_null() { | |||
Measure.updatedMeasureBuilder(newMeasureBuilder().createNoValue()).setQualityGateStatus(null); | |||
assertThatThrownBy(() -> { | |||
Measure.updatedMeasureBuilder(newMeasureBuilder().createNoValue()).setQualityGateStatus(null); | |||
}) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = UnsupportedOperationException.class) | |||
@Test | |||
public void updateMeasureBuilder_setQualityGateStatus_throws_USO_if_measure_already_has_a_QualityGateStatus() { | |||
QualityGateStatus qualityGateStatus = new QualityGateStatus(Measure.Level.ERROR); | |||
Measure.updatedMeasureBuilder(newMeasureBuilder().setQualityGateStatus(qualityGateStatus).createNoValue()).setQualityGateStatus(qualityGateStatus); | |||
assertThatThrownBy(() -> { | |||
QualityGateStatus qualityGateStatus = new QualityGateStatus(Measure.Level.ERROR); | |||
Measure.updatedMeasureBuilder(newMeasureBuilder().setQualityGateStatus(qualityGateStatus).createNoValue()).setQualityGateStatus(qualityGateStatus); | |||
}) | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
@Test(expected = UnsupportedOperationException.class) | |||
@Test | |||
public void updateMeasureBuilder_setVariations_throws_USO_if_measure_already_has_Variations() { | |||
Measure.updatedMeasureBuilder(newMeasureBuilder().setVariation(1d).createNoValue()).setVariation(2d); | |||
assertThatThrownBy(() -> Measure.updatedMeasureBuilder(newMeasureBuilder().setVariation(1d).createNoValue()).setVariation(2d)) | |||
.isInstanceOf(UnsupportedOperationException.class); | |||
} | |||
@Test | |||
@@ -281,18 +293,16 @@ public class MeasureTest { | |||
@Test | |||
public void create_with_double_value_throws_IAE_if_value_is_NaN() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("NaN is not allowed as a Measure value"); | |||
newMeasureBuilder().create(Double.NaN, 1); | |||
assertThatThrownBy(() -> newMeasureBuilder().create(Double.NaN, 1)) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("NaN is not allowed as a Measure value"); | |||
} | |||
@Test | |||
public void create_with_double_value_data_throws_IAE_if_value_is_NaN() { | |||
expectedException.expect(IllegalArgumentException.class); | |||
expectedException.expectMessage("NaN is not allowed as a Measure value"); | |||
newMeasureBuilder().create(Double.NaN, 1, "some data"); | |||
assertThatThrownBy(() -> newMeasureBuilder().create(Double.NaN, 1, "some data")) | |||
.isInstanceOf(IllegalArgumentException.class) | |||
.hasMessage("NaN is not allowed as a Measure value"); | |||
} | |||
} |
@@ -36,6 +36,7 @@ import org.sonar.db.measure.LiveMeasureDto; | |||
import org.sonar.db.measure.MeasureDto; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
@RunWith(DataProviderRunner.class) | |||
public class MeasureToMeasureDtoTest { | |||
@@ -65,14 +66,16 @@ public class MeasureToMeasureDtoTest { | |||
analysisMetadataHolder.setUuid(ANALYSIS_UUID); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasureDto_throws_NPE_if_Measure_arg_is_null() { | |||
underTest.toMeasureDto(null, SOME_METRIC, SOME_COMPONENT); | |||
assertThatThrownBy(() -> underTest.toMeasureDto(null, SOME_METRIC, SOME_COMPONENT)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@Test(expected = NullPointerException.class) | |||
@Test | |||
public void toMeasureDto_throws_NPE_if_Metric_arg_is_null() { | |||
underTest.toMeasureDto(Measure.newMeasureBuilder().createNoValue(), null, SOME_COMPONENT); | |||
assertThatThrownBy(() -> underTest.toMeasureDto(Measure.newMeasureBuilder().createNoValue(), null, SOME_COMPONENT)) | |||
.isInstanceOf(NullPointerException.class); | |||
} | |||
@DataProvider |
@@ -21,7 +21,6 @@ package org.sonar.ce.task.projectanalysis.measure; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.mockito.ArgumentCaptor; | |||
import org.mockito.InOrder; | |||
import org.sonar.api.measures.CoreMetrics; | |||
@@ -54,8 +53,6 @@ public class PostMeasuresComputationChecksStepTest { | |||
public MeasureRepositoryRule measureRepository = MeasureRepositoryRule.create(treeRootHolder, metricRepository); | |||
@Rule | |||
public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule(); | |||
@Rule | |||
public ExpectedException expectedException = ExpectedException.none(); | |||
@Test | |||
public void execute_extensions() { |