diff options
author | Klaudio Sinani <klaudio.sinani@sonarsource.com> | 2021-11-17 22:54:06 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-11-19 20:03:27 +0000 |
commit | a3d88ea27c35921647d7602755828ca73e15e865 (patch) | |
tree | 5626c38afab1ea00ab9897da431476c17b478bbe /sonar-scanner-engine/src | |
parent | 92f482f2aa43e4aa36e0fda377d13b9dc3282ff9 (diff) | |
download | sonarqube-a3d88ea27c35921647d7602755828ca73e15e865.tar.gz sonarqube-a3d88ea27c35921647d7602755828ca73e15e865.zip |
SONAR-15631 - Refactor UTs to stop using ExpectedException
Diffstat (limited to 'sonar-scanner-engine/src')
50 files changed, 365 insertions, 629 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java index b9a4b4d0c1e..5d12e1eafd0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java @@ -21,18 +21,17 @@ package org.sonar.scanner; import java.util.List; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; -import org.sonar.api.batch.measure.MetricFinder; -import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.batch.measure.MetricFinder; +import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.measures.CoreMetrics; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -47,9 +46,6 @@ public class DefaultFileLinesContextTest { private static final String AUTHOR_METRIC_KEY = "author"; private static final String BRANCHES_METRIC_KEY = "branches"; - @Rule - public ExpectedException thrown = ExpectedException.none(); - private DefaultFileLinesContext fileLineMeasures; private SensorStorage sensorStorage; @@ -96,14 +92,14 @@ public class DefaultFileLinesContextTest { @Test public void validateLineGreaterThanZero() { - thrown.expectMessage("Line number should be positive for file src/foo.php."); - fileLineMeasures.setIntValue(HITS_METRIC_KEY, 0, 2); + assertThatThrownBy(() -> fileLineMeasures.setIntValue(HITS_METRIC_KEY, 0, 2)) + .hasMessage("Line number should be positive for file src/foo.php."); } @Test public void validateLineLowerThanLineCount() { - thrown.expectMessage("Line 4 is out of range for file src/foo.php. File has 3 lines"); - fileLineMeasures.setIntValue(HITS_METRIC_KEY, 4, 2); + assertThatThrownBy(() -> fileLineMeasures.setIntValue(HITS_METRIC_KEY, 4, 2)) + .hasMessageContaining("Line 4 is out of range for file src/foo.php. File has 3 lines"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectInfoTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectInfoTest.java index fd379bf276e..fbcf7f2ecd8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectInfoTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/ProjectInfoTest.java @@ -30,9 +30,7 @@ import java.time.ZoneOffset; import java.util.Date; import javax.annotation.Nullable; import org.apache.commons.lang.RandomStringUtils; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.sonar.api.CoreProperties; import org.sonar.api.config.internal.MapSettings; @@ -40,14 +38,12 @@ import org.sonar.api.utils.MessageException; 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.mockito.Mockito.mock; @RunWith(DataProviderRunner.class) public class ProjectInfoTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - private MapSettings settings = new MapSettings(); private Clock clock = mock(Clock.class); private ProjectInfo underTest = new ProjectInfo(settings.asConfig(), clock); @@ -80,9 +76,8 @@ public class ProjectInfoTest { settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, ""); settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, "version"); - expectedException.expect(RuntimeException.class); - - underTest.start(); + assertThatThrownBy(() -> underTest.start()) + .isInstanceOf(RuntimeException.class); } @Test @@ -91,11 +86,10 @@ public class ProjectInfoTest { settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); settings.setProperty(CoreProperties.PROJECT_VERSION_PROPERTY, version); - expectedException.expect(MessageException.class); - expectedException.expectMessage("\"" + version + "\" is not a valid project version. " + - "The maximum length is 100 characters."); - - underTest.start(); + assertThatThrownBy(() -> underTest.start()) + .isInstanceOf(MessageException.class) + .hasMessage("\"" + version + "\" is not a valid project version. " + + "The maximum length is 100 characters."); } @Test @@ -104,11 +98,10 @@ public class ProjectInfoTest { settings.setProperty(CoreProperties.PROJECT_DATE_PROPERTY, "2017-01-01"); settings.setProperty(CoreProperties.BUILD_STRING_PROPERTY, buildString); - expectedException.expect(MessageException.class); - expectedException.expectMessage("\"" + buildString + "\" is not a valid buildString. " + - "The maximum length is 100 characters."); - - underTest.start(); + assertThatThrownBy(() -> underTest.start()) + .isInstanceOf(MessageException.class) + .hasMessage("\"" + buildString + "\" is not a valid buildString. " + + "The maximum length is 100 characters."); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java index edb626dc205..4896e77c230 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/DefaultScannerWsClientTest.java @@ -24,7 +24,6 @@ import java.util.List; import org.apache.commons.lang.StringUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.Mockito; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.LogTester; @@ -37,6 +36,7 @@ import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; 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; @@ -45,9 +45,6 @@ public class DefaultScannerWsClientTest { @Rule public LogTester logTester = new LogTester(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); - WsClient wsClient = mock(WsClient.class, Mockito.RETURNS_DEEP_STUBS); @Test @@ -91,54 +88,54 @@ public class DefaultScannerWsClientTest { @Test public void fail_if_requires_credentials() { - expectedException.expect(MessageException.class); - expectedException - .expectMessage("Not authorized. Analyzing this project requires authentication. Please provide a user token in sonar.login or other credentials in sonar.login and sonar.password."); - WsRequest request = newRequest(); WsResponse response = newResponse().setCode(401); when(wsClient.wsConnector().call(request)).thenReturn(response); - new DefaultScannerWsClient(wsClient, false, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request); + assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, false, + new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request)) + .isInstanceOf(MessageException.class) + .hasMessage("Not authorized. Analyzing this project requires authentication. Please provide a user token in sonar.login or other " + + "credentials in sonar.login and sonar.password."); } @Test public void fail_if_credentials_are_not_valid() { - expectedException.expect(MessageException.class); - expectedException.expectMessage("Not authorized. Please check the properties sonar.login and sonar.password."); - WsRequest request = newRequest(); WsResponse response = newResponse().setCode(401); when(wsClient.wsConnector().call(request)).thenReturn(response); - new DefaultScannerWsClient(wsClient, /* credentials are configured */true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request); + assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, /* credentials are configured */true, + new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request)) + .isInstanceOf(MessageException.class) + .hasMessage("Not authorized. Please check the properties sonar.login and sonar.password."); } @Test public void fail_if_requires_permission() { - expectedException.expect(MessageException.class); - expectedException.expectMessage("You're not authorized to run analysis. Please contact the project administrator."); - WsRequest request = newRequest(); WsResponse response = newResponse() .setCode(403); when(wsClient.wsConnector().call(request)).thenReturn(response); - new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request); + assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, true, + new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request)) + .isInstanceOf(MessageException.class) + .hasMessage("You're not authorized to run analysis. Please contact the project administrator."); } @Test public void fail_if_bad_request() { - expectedException.expect(MessageException.class); - expectedException.expectMessage("Boo! bad request! bad!"); - WsRequest request = newRequest(); WsResponse response = newResponse() .setCode(400) .setContent("{\"errors\":[{\"msg\":\"Boo! bad request! bad!\"}]}"); when(wsClient.wsConnector().call(request)).thenReturn(response); - new DefaultScannerWsClient(wsClient, true, new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request); + assertThatThrownBy(() -> new DefaultScannerWsClient(wsClient, true, + new GlobalAnalysisMode(new ScannerProperties(Collections.emptyMap()))).call(request)) + .isInstanceOf(MessageException.class) + .hasMessage("Boo! bad request! bad!"); } private MockWsResponse newResponse() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java index bcae1883052..adaec06e8cf 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalConfigurationProviderTest.java @@ -24,7 +24,6 @@ import java.util.Collections; 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.utils.System2; import org.sonar.api.utils.log.LogTester; @@ -36,8 +35,6 @@ import static org.mockito.Mockito.when; public class GlobalConfigurationProviderTest { @Rule - public ExpectedException thrown = ExpectedException.none(); - @Rule public LogTester logTester = new LogTester(); GlobalServerSettings globalServerSettings; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java index e350552b430..ae65480b996 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/PluginFilesTest.java @@ -43,12 +43,9 @@ import okio.Buffer; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.RandomStringUtils; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; 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.config.internal.MapSettings; import org.sonar.scanner.bootstrap.ScannerPluginInstaller.InstalledPlugin; @@ -57,12 +54,12 @@ import org.sonarqube.ws.client.WsClientFactories; import static org.apache.commons.io.FileUtils.moveFile; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.ThrowableAssert.ThrowingCallable; public class PluginFilesTest { @Rule - public ExpectedException expectedException = ExpectedException.none(); - @Rule public TemporaryFolder temp = new TemporaryFolder(); @Rule public MockWebServer server = new MockWebServer(); @@ -147,9 +144,8 @@ public class PluginFilesTest { enqueueDownload(tempJar.file, "invalid_hash"); InstalledPlugin plugin = newInstalledPlugin("foo", "abc"); - expectISE("foo", "was expected to have checksum invalid_hash but had " + tempJar.md5); - - underTest.get(plugin); + expectISE("foo", "was expected to have checksum invalid_hash but had " + tempJar.md5, + () -> underTest.get(plugin)); } @Test @@ -157,10 +153,9 @@ public class PluginFilesTest { FileAndMd5 jar = new FileAndMd5(); enqueueCompressedDownload(jar, false); - expectISE("foo", "was expected to have checksum invalid_hash but had "); InstalledPlugin plugin = newInstalledPlugin("foo", jar.md5); - underTest.get(plugin).get(); + expectISE("foo", "was expected to have checksum invalid_hash but had ", () -> underTest.get(plugin).get()); } @Test @@ -169,9 +164,7 @@ public class PluginFilesTest { enqueueDownload(tempJar, null); InstalledPlugin plugin = newInstalledPlugin("foo", "abc"); - expectISE("foo", "did not return header Sonar-MD5"); - - underTest.get(plugin); + expectISE("foo", "did not return header Sonar-MD5", () -> underTest.get(plugin)); } @Test @@ -182,10 +175,9 @@ public class PluginFilesTest { response.setHeader("Sonar-Compression", "pack200"); server.enqueue(response); - expectISE("foo", "Pack200 error"); - InstalledPlugin plugin = newInstalledPlugin("foo", "abc"); - underTest.get(plugin).get(); + + expectISE("foo", "Pack200 error", () -> underTest.get(plugin).get()); } @Test @@ -193,9 +185,7 @@ public class PluginFilesTest { server.enqueue(new MockResponse().setResponseCode(500)); InstalledPlugin plugin = newInstalledPlugin("foo", "abc"); - expectISE("foo", "returned code 500"); - - underTest.get(plugin); + expectISE("foo", "returned code 500", () -> underTest.get(plugin)); } @Test @@ -229,10 +219,9 @@ public class PluginFilesTest { InstalledPlugin plugin = newInstalledPlugin("foo/bar", "abc"); - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to download plugin [foo/bar]. Key is not valid."); - - underTest.get(plugin); + assertThatThrownBy(() -> underTest.get(plugin)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Fail to download plugin [foo/bar]. Key is not valid."); } private FileAndMd5 createFileInCache(String pluginKey) throws IOException { @@ -274,7 +263,7 @@ public class PluginFilesTest { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(jar.file.toPath()))); - OutputStream output = new GZIPOutputStream(new BufferedOutputStream(bytes))) { + OutputStream output = new GZIPOutputStream(new BufferedOutputStream(bytes))) { Pack200.newPacker().pack(in, output); } body.write(bytes.toByteArray()); @@ -311,13 +300,13 @@ public class PluginFilesTest { private File packAndUnpackJar(File source) throws IOException { File packed = temp.newFile(); try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(source.toPath()))); - OutputStream out = new GZIPOutputStream(new BufferedOutputStream(Files.newOutputStream(packed.toPath())))) { + OutputStream out = new GZIPOutputStream(new BufferedOutputStream(Files.newOutputStream(packed.toPath())))) { Pack200.newPacker().pack(in, out); } File to = temp.newFile(); try (InputStream input = new GZIPInputStream(new BufferedInputStream(Files.newInputStream(packed.toPath()))); - JarOutputStream output = new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(to.toPath())))) { + JarOutputStream output = new JarOutputStream(new BufferedOutputStream(Files.newOutputStream(to.toPath())))) { Pack200.newUnpacker().unpack(input, output); } catch (IOException e) { throw new IllegalStateException(e); @@ -326,18 +315,11 @@ public class PluginFilesTest { return to; } - private void expectISE(String pluginKey, String message) { - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage(new TypeSafeMatcher<String>() { - @Override - protected boolean matchesSafely(String item) { - return item.startsWith("Fail to download plugin [" + pluginKey + "]") && item.contains(message); - } - - @Override - public void describeTo(Description description) { - } - }); + private void expectISE(String pluginKey, String message, ThrowingCallable shouldRaiseThrowable) { + assertThatThrownBy(shouldRaiseThrowable) + .isInstanceOf(IllegalStateException.class) + .hasMessageStartingWith("Fail to download plugin [" + pluginKey + "]") + .hasMessageContaining(message); } private class FileAndMd5 { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java index 259a8db6a6c..7c80e9e30cc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/ScannerPluginInstallerTest.java @@ -31,11 +31,11 @@ import java.util.jar.Manifest; import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.WsTestUtil; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; @@ -44,8 +44,6 @@ public class ScannerPluginInstallerTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); private PluginFiles pluginFiles = mock(PluginFiles.class); private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class); @@ -75,10 +73,9 @@ public class ScannerPluginInstallerTest { public void fail_if_json_of_installed_plugins_is_not_valid() { WsTestUtil.mockReader(wsClient, "api/plugins/installed", new StringReader("not json")); - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to parse response of api/plugins/installed"); - - underTest.installRemotes(); + assertThatThrownBy(() -> underTest.installRemotes()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Fail to parse response of api/plugins/installed"); } @Test @@ -104,10 +101,9 @@ public class ScannerPluginInstallerTest { enqueueDownload("cobol", "ghi"); enqueueNotFoundDownload("java", "def"); - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Fail to download plugin [java]. Not found."); - - underTest.installRemotes(); + assertThatThrownBy(() -> underTest.installRemotes()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Fail to download plugin [java]. Not found."); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java index dfb992a153e..4c50ee85789 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/cpd/CpdExecutorTest.java @@ -33,10 +33,12 @@ import javax.annotation.Nullable; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.mockito.ArgumentMatchers; import org.sonar.api.SonarRuntime; +import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.DefaultInputProject; +import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.core.util.CloseableIterator; @@ -45,9 +47,6 @@ import org.sonar.duplications.block.ByteArray; import org.sonar.duplications.index.CloneGroup; import org.sonar.duplications.index.ClonePart; import org.sonar.scanner.cpd.index.SonarCpdBlockIndex; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.batch.fs.internal.DefaultInputProject; -import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.scanner.protocol.output.ScannerReport.Duplicate; import org.sonar.scanner.protocol.output.ScannerReport.Duplication; import org.sonar.scanner.protocol.output.ScannerReportReader; @@ -69,9 +68,6 @@ public class CpdExecutorTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private CpdExecutor executor; private final ExecutorService executorService = mock(ExecutorService.class); private final CpdSettings settings = mock(CpdSettings.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java index e35482fc624..d30cac61351 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/externalissue/ReportParserTest.java @@ -21,16 +21,13 @@ package org.sonar.scanner.externalissue; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.scanner.externalissue.ReportParser.Report; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class ReportParserTest { - @Rule - public ExpectedException exception = ExpectedException.none(); @Test public void parse_sample() { @@ -73,72 +70,81 @@ public class ReportParserTest { @Test public void fail_if_report_doesnt_exist() { ReportParser parser = new ReportParser(Paths.get("unknown.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("Failed to read external issues report 'unknown.json'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Failed to read external issues report 'unknown.json'"); } @Test public void fail_if_report_is_not_valid_json() { ReportParser parser = new ReportParser(path("report_invalid_json.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("invalid JSON syntax"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("invalid JSON syntax"); } @Test public void fail_if_primaryLocation_not_set() { ReportParser parser = new ReportParser(path("report_missing_primaryLocation.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'primaryLocation'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'primaryLocation'"); } @Test public void fail_if_engineId_not_set() { ReportParser parser = new ReportParser(path("report_missing_engineId.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'engineId'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'engineId'"); } @Test public void fail_if_ruleId_not_set() { ReportParser parser = new ReportParser(path("report_missing_ruleId.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'ruleId'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'ruleId'"); } @Test public void fail_if_severity_not_set() { ReportParser parser = new ReportParser(path("report_missing_severity.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'severity'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'severity'"); } @Test public void fail_if_type_not_set() { ReportParser parser = new ReportParser(path("report_missing_type.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'type'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'type'"); } @Test public void fail_if_filePath_not_set_in_primaryLocation() { ReportParser parser = new ReportParser(path("report_missing_filePath.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'filePath'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'filePath'"); } - + @Test public void fail_if_message_not_set_in_primaryLocation() { ReportParser parser = new ReportParser(path("report_missing_message.json")); - exception.expect(IllegalStateException.class); - exception.expectMessage("missing mandatory field 'message'"); - parser.parse(); + + assertThatThrownBy(() -> parser.parse()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("missing mandatory field 'message'"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java index c147a7f970b..6a51e1e7816 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/issue/ignore/scanner/IssueExclusionsLoaderTest.java @@ -22,14 +22,12 @@ package org.sonar.scanner.issue.ignore.scanner; import java.util.Arrays; import java.util.Collections; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.sonar.api.notifications.AnalysisWarnings; import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; +import org.sonar.api.notifications.AnalysisWarnings; import org.sonar.scanner.issue.ignore.IgnoreIssuesFilter; import org.sonar.scanner.issue.ignore.pattern.IssueExclusionPatternInitializer; import org.sonar.scanner.issue.ignore.pattern.IssuePattern; @@ -42,9 +40,6 @@ import static org.mockito.Mockito.when; public class IssueExclusionsLoaderTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - @Mock private IssueExclusionPatternInitializer exclusionPatternInitializer; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java index b0308f2ce66..9babf2fe95b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/DeprecatedBranchMediumTest.java @@ -27,22 +27,20 @@ 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.utils.MessageException; import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + public class DeprecatedBranchMediumTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addRules(new XooRulesDefinition()) @@ -77,15 +75,14 @@ public class DeprecatedBranchMediumTest { File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent"); - thrown.expect(MessageException.class); - thrown.expectMessage("The 'sonar.branch' parameter is no longer supported. You should stop using it. " + - "Branch analysis is available in Developer Edition and above. See https://redirect.sonarsource.com/editions/developer.html for more information."); - - tester.newAnalysis() + assertThatThrownBy(() -> tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .putAll(commonProps) .put("sonar.branch", "branch") .build()) - .execute(); + .execute()) + .isInstanceOf(MessageException.class) + .hasMessage("The 'sonar.branch' parameter is no longer supported. You should stop using it. " + + "Branch analysis is available in Developer Edition and above. See https://redirect.sonarsource.com/editions/developer.html for more information."); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java index 28658650636..d0c29a346c3 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/cpd/CpdMediumTest.java @@ -28,7 +28,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.utils.log.LogTester; @@ -46,9 +45,6 @@ public class CpdMediumTest { public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); private File baseDir; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java index 08fb1328223..8ce1a2dcf9b 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java @@ -31,7 +31,6 @@ import org.apache.commons.lang.StringUtils; 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.CoreProperties; import org.sonar.api.SonarEdition; @@ -49,8 +48,8 @@ import org.sonar.xoo.global.DeprecatedGlobalSensor; import org.sonar.xoo.global.GlobalProjectSensor; import org.sonar.xoo.rule.XooRulesDefinition; -import static java.util.stream.Collectors.joining; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assume.assumeTrue; public class FileSystemMediumTest { @@ -59,9 +58,6 @@ public class FileSystemMediumTest { public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); @Rule @@ -118,13 +114,12 @@ public class FileSystemMediumTest { assertThat(srcDir.mkdir()).isTrue(); // Using sonar.branch.name when the branch plugin is not installed is an error. - thrown.expect(MessageException.class); - - tester.newAnalysis() + assertThatThrownBy(() -> tester.newAnalysis() .properties(builder .put("sonar.sources", "src") .build()) - .execute(); + .execute()) + .isInstanceOf(MessageException.class); } @Test @@ -210,10 +205,9 @@ public class FileSystemMediumTest { assertThat(logTester.logs()).doesNotContain("'src/test/sample.java' generated metadata", "'src\\test\\sample.java' generated metadata"); DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java"); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Unable to find report for component"); - - result.getReportComponent(javaInputFile); + assertThatThrownBy(() -> result.getReportComponent(javaInputFile)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Unable to find report for component"); } @Test @@ -693,13 +687,13 @@ public class FileSystemMediumTest { File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent", StandardCharsets.UTF_8); - thrown.expect(MessageException.class); - thrown.expectMessage("File src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files"); - tester.newAnalysis() + assertThatThrownBy(() -> tester.newAnalysis() .properties(builder .put("sonar.sources", "src,src/sample.xoo") .build()) - .execute(); + .execute()) + .isInstanceOf(MessageException.class) + .hasMessage("File src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files"); } // SONAR-9574 @@ -711,16 +705,15 @@ public class FileSystemMediumTest { File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent", StandardCharsets.UTF_8); - thrown.expect(MessageException.class); - thrown.expectMessage("File module1/src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files"); - tester.newAnalysis() + assertThatThrownBy(() -> tester.newAnalysis() .properties(builder .put("sonar.sources", "module1/src") .put("sonar.modules", "module1") .put("module1.sonar.sources", "src") .build()) - .execute(); - + .execute()) + .isInstanceOf(MessageException.class) + .hasMessage("File module1/src/sample.xoo can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files"); } // SONAR-5330 @@ -778,9 +771,9 @@ public class FileSystemMediumTest { "TESTX/ClassOneTest.xoo.scm", "XOURCES/hello/HelloJava.xoo"); } else { - thrown.expect(MessageException.class); - thrown.expectMessage("The folder 'TESTX' does not exist for 'sample'"); - analysis.execute(); + assertThatThrownBy(() -> analysis.execute()) + .isInstanceOf(MessageException.class) + .hasMessageContaining("The folder 'TESTX' does not exist for 'sample'"); } } @@ -954,8 +947,7 @@ public class FileSystemMediumTest { .execute(); assertThat(logTester.logs(LoggerLevel.INFO)) - .containsSequence("Indexing files...", - "Project configuration:", + .containsSequence("Project configuration:", " Included sources: **/global.inclusions", " Excluded sources: **/global.exclusions, **/global.test.inclusions", " Included tests: **/global.test.inclusions", diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java index 98ed1109d3a..ab5757b20fd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/NoLanguagesPluginsMediumTest.java @@ -24,30 +24,27 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.FileFilterUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.scanner.mediumtest.ScannerMediumTester; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + public class NoLanguagesPluginsMediumTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException exception = ExpectedException.none(); - - @Rule public ScannerMediumTester tester = new ScannerMediumTester(); @Test public void testNoLanguagePluginsInstalled() throws Exception { File projectDir = copyProject("test-resources/mediumtest/xoo/sample"); - exception.expect(IllegalStateException.class); - exception.expectMessage("No language plugins are installed"); - - tester + assertThatThrownBy(() -> tester .newAnalysis(new File(projectDir, "sonar-project.properties")) - .execute(); + .execute()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("No language plugins are installed."); } private File copyProject(String path) throws Exception { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java index bfde29a5d51..09538ea8e18 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/ProjectBuilderMediumTest.java @@ -24,11 +24,8 @@ import java.io.File; import java.io.IOException; import java.util.List; import org.apache.commons.io.FileUtils; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.SonarEdition; import org.sonar.api.batch.bootstrap.ProjectBuilder; @@ -40,6 +37,7 @@ import org.sonar.xoo.XooPlugin; import org.sonar.xoo.rule.XooRulesDefinition; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.Assertions.tuple; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; @@ -50,9 +48,6 @@ public class ProjectBuilderMediumTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException exception = ExpectedException.none(); - private ProjectBuilder projectBuilder = mock(ProjectBuilder.class); @Rule @@ -82,33 +77,18 @@ public class ProjectBuilderMediumTest { File baseDir = prepareProject(); doThrow(new IllegalStateException("My error message")).when(projectBuilder).build(any(ProjectBuilder.Context.class)); - exception.expectMessage("Failed to execute project builder"); - exception.expect(MessageException.class); - exception.expectCause(new BaseMatcher<Throwable>() { - - @Override - public boolean matches(Object item) { - if (!(item instanceof IllegalStateException)) { - return false; - } - IllegalStateException e = (IllegalStateException) item; - return "My error message".equals(e.getMessage()); - } - - @Override - public void describeTo(Description description) { - } - }); - - tester.newAnalysis() + + assertThatThrownBy(() -> tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") .put("sonar.sources", ".") .put("sonar.xoo.enableProjectBuilder", "true") .build()) - .execute(); - + .execute()) + .isInstanceOf(MessageException.class) + .hasMessageContaining("Failed to execute project builder") + .hasCauseInstanceOf(IllegalStateException.class); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java index 84eeccad942..3c7872807db 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/highlighting/HighlightingMediumTest.java @@ -23,19 +23,18 @@ import com.google.common.collect.ImmutableMap; import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; 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.sensor.highlighting.TypeOfText; -import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.scanner.mediumtest.AnalysisResult; +import org.sonar.scanner.mediumtest.ScannerMediumTester; import org.sonar.xoo.XooPlugin; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder; public class HighlightingMediumTest { @@ -43,9 +42,6 @@ public class HighlightingMediumTest { public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException exception = ExpectedException.none(); - - @Rule public ScannerMediumTester tester = new ScannerMediumTester() .registerPlugin("xoo", new XooPlugin()) .addDefaultQProfile("xoo", "Sonar Way"); @@ -89,9 +85,7 @@ public class HighlightingMediumTest { File xooFile = new File(srcDir, "sample.xoo"); FileUtils.write(xooFile, "Sample xoo\ncontent plop"); - exception.expect(UnsupportedOperationException.class); - exception.expectMessage("Trying to save highlighting twice for the same file is not supported"); - tester.newAnalysis() + AnalysisBuilder analysisBuilder = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") @@ -100,9 +94,11 @@ public class HighlightingMediumTest { .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") .put("sonar.it.savedatatwice", "true") - .build()) - .execute(); + .build());; + assertThatThrownBy(() -> analysisBuilder.execute()) + .isInstanceOf(UnsupportedOperationException.class) + .hasMessageContaining("Trying to save highlighting twice for the same file is not supported"); } @Test @@ -117,21 +113,7 @@ public class HighlightingMediumTest { FileUtils.write(xooFile, "Sample xoo\ncontent plop"); FileUtils.write(xoohighlightingFile, "1:0:1:10:s\n2:18:2:18:k"); - exception.expect(IllegalStateException.class); - exception.expectMessage("Error processing line 2"); - exception.expectCause(new TypeSafeMatcher<IllegalArgumentException>() { - @Override - public void describeTo(Description description) { - description.appendText("Invalid cause"); - } - - @Override - protected boolean matchesSafely(IllegalArgumentException e) { - return e.getMessage().contains("Unable to highlight file"); - } - }); - - tester.newAnalysis() + AnalysisBuilder analysisBuilder = tester.newAnalysis() .properties(ImmutableMap.<String, String>builder() .put("sonar.projectBaseDir", baseDir.getAbsolutePath()) .put("sonar.projectKey", "com.foo.project") @@ -139,8 +121,12 @@ public class HighlightingMediumTest { .put("sonar.projectVersion", "1.0-SNAPSHOT") .put("sonar.projectDescription", "Description of Foo Project") .put("sonar.sources", "src") - .build()) - .execute(); + .build()); + + assertThatThrownBy(() -> analysisBuilder.execute()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Error processing line 2") + .hasCauseInstanceOf(IllegalArgumentException.class); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/PreviewMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/PreviewMediumTest.java index bd6296374fa..3fb6206888c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/PreviewMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/issues/PreviewMediumTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.mediumtest.issues; import com.google.common.collect.ImmutableMap; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.log.LogTester; import org.sonar.scanner.mediumtest.ScannerMediumTester; @@ -33,9 +32,6 @@ import static org.assertj.core.api.Assertions.fail; public class PreviewMediumTest { @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java index e9a2fbe0b01..22823ec68ba 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/ExceptionHandlingMediumTest.java @@ -21,21 +21,16 @@ package org.sonar.scanner.mediumtest.log; import java.util.Collections; import java.util.Map; -import org.hamcrest.CoreMatchers; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; import org.junit.BeforeClass; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.utils.MessageException; import org.sonar.batch.bootstrapper.Batch; import org.sonar.batch.bootstrapper.EnvironmentInformation; import org.sonar.scanner.repository.settings.GlobalSettingsLoader; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + public class ExceptionHandlingMediumTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); private Batch batch; private static ErrorGlobalSettingsLoader loader; @@ -62,11 +57,10 @@ public class ExceptionHandlingMediumTest { public void test() throws Exception { setUp(false); loader.withCause = false; - thrown.expect(MessageException.class); - thrown.expectMessage("Error loading settings"); - thrown.expectCause(CoreMatchers.nullValue(Throwable.class)); - batch.execute(); + assertThatThrownBy(() -> batch.execute()) + .isInstanceOf(MessageException.class) + .hasMessage("Error loading settings"); } @Test @@ -74,28 +68,20 @@ public class ExceptionHandlingMediumTest { setUp(false); loader.withCause = true; - thrown.expect(MessageException.class); - thrown.expectMessage("Error loading settings"); - thrown.expectCause(new TypeSafeMatcher<Throwable>() { - @Override - public void describeTo(Description description) { - } - - @Override - protected boolean matchesSafely(Throwable item) { - return item instanceof IllegalStateException && item.getMessage().equals("Code 401"); - } - }); - - batch.execute(); + assertThatThrownBy(() -> batch.execute()) + .isInstanceOf(MessageException.class) + .hasMessage("Error loading settings") + .hasCauseInstanceOf(Throwable.class) + .hasRootCauseMessage("Code 401"); } @Test - public void testWithVerbose() throws Exception { + public void testWithVerbose() { setUp(true); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Unable to load component class"); - batch.execute(); + + assertThatThrownBy(() -> batch.execute()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Unable to load component class"); } private static class ErrorGlobalSettingsLoader implements GlobalSettingsLoader { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java index 0bf5239b3c0..100c19c8ae2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/log/LogListenerTest.java @@ -36,7 +36,6 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.batch.bootstrapper.LogOutput; import org.sonar.batch.bootstrapper.LogOutput.Level; @@ -50,9 +49,6 @@ public class LogListenerTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private Pattern simpleTimePattern = Pattern.compile("\\d{2}:\\d{2}:\\d{2}"); private List<LogEvent> logOutput; private StringBuilder logOutputStr; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java index cba5f6687b5..9e29806ef95 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/scm/ScmMediumTest.java @@ -30,7 +30,6 @@ import org.apache.commons.io.FileUtils; import org.assertj.core.util.Files; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.sonar.api.SonarEdition; import org.sonar.api.utils.log.LogTester; @@ -59,9 +58,6 @@ public class ScmMediumTest { public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java index a89131c6f39..948a55eee42 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/tasks/TasksMediumTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.mediumtest.tasks; import com.google.common.collect.ImmutableMap; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.Plugin; import org.sonar.api.task.Task; import org.sonar.api.task.TaskDefinition; @@ -36,9 +35,6 @@ import static org.assertj.core.api.Assertions.fail; public class TasksMediumTest { @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); @Rule diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java index 104c1bf322a..2291672a259 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/postjob/PostJobOptimizerTest.java @@ -20,19 +20,14 @@ package org.sonar.scanner.postjob; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.sonar.api.config.internal.MapSettings; import org.sonar.api.batch.postjob.internal.DefaultPostJobDescriptor; +import org.sonar.api.config.internal.MapSettings; import static org.assertj.core.api.Assertions.assertThat; public class PostJobOptimizerTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - private PostJobOptimizer optimizer; private MapSettings settings; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java index 587b9d10b21..7f73a26aab8 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/qualitygate/QualityGateCheckTest.java @@ -25,7 +25,6 @@ import com.tngtech.java.junit.dataprovider.UseDataProvider; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; @@ -44,6 +43,7 @@ import org.sonarqube.ws.client.MockWsResponse; import org.sonarqube.ws.client.WsRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -60,9 +60,6 @@ public class QualityGateCheckTest { @Rule public LogTester logTester = new LogTester(); - @Rule - public ExpectedException exception = ExpectedException.none(); - QualityGateCheck underTest = new QualityGateCheck(wsClient, analysisMode, reportMetadataHolder, properties); @Before @@ -127,9 +124,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com"); } @Test @@ -145,9 +142,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com"); } @Test @@ -164,10 +161,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com"); - - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessage("QUALITY GATE STATUS: FAILED - View details on http://dashboard-url.com"); } @Test @@ -180,9 +176,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("Quality Gate check timeout exceeded - View details on http://dashboard-url.com"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessage("Quality Gate check timeout exceeded - View details on http://dashboard-url.com"); } @Test @@ -197,9 +193,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("Failed to get Quality Gate status - HTTP code 400: content"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessage("Failed to get Quality Gate status - HTTP code 400: content"); } @Test @@ -217,9 +213,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(IllegalStateException.class); - exception.expectMessage("Failed to parse response from quality-gate-url"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Failed to parse response from quality-gate-url"); } @Test @@ -231,9 +227,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("Failed to get CE Task status - HTTP code 400: content"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessage("Failed to get CE Task status - HTTP code 400: content"); } @Test @@ -249,9 +245,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(IllegalStateException.class); - exception.expectMessage("Failed to parse response from ce-task-url"); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Failed to parse response from ce-task-url"); } @Test @@ -265,9 +261,9 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(MessageException.class); - exception.expectMessage("CE Task finished abnormally with status: " + taskStatus.name()); - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(MessageException.class) + .hasMessageContaining("CE Task finished abnormally with status: " + taskStatus.name()); } private WsRequest newGetCeTaskRequest() { @@ -302,9 +298,8 @@ public class QualityGateCheckTest { underTest.start(); - exception.expect(IllegalStateException.class); - - underTest.await(); + assertThatThrownBy(() -> underTest.await()) + .isInstanceOf(IllegalStateException.class); } private WsRequest newGetQualityGateRequest() { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CeTaskReportDataHolderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CeTaskReportDataHolderTest.java index 958717e6409..1e1560cbd9f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CeTaskReportDataHolderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/CeTaskReportDataHolderTest.java @@ -19,17 +19,13 @@ */ package org.sonar.scanner.report; -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 CeTaskReportDataHolderTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - CeTaskReportDataHolder underTest = new CeTaskReportDataHolder(); @Test @@ -45,19 +41,19 @@ public class CeTaskReportDataHolderTest { @Test public void getCeTaskId_should_fail_if_not_initialized() { - exception.expect(IllegalStateException.class); - underTest.getCeTaskId(); + assertThatThrownBy(() -> underTest.getCeTaskId()) + .isInstanceOf(IllegalStateException.class); } @Test public void getCeTaskUrl_should_fail_if_not_initialized() { - exception.expect(IllegalStateException.class); - underTest.getCeTaskUrl(); + assertThatThrownBy(() -> underTest.getCeTaskUrl()) + .isInstanceOf(IllegalStateException.class); } @Test public void getDashboardUrl_should_fail_if_not_initialized() { - exception.expect(IllegalStateException.class); - underTest.getDashboardUrl(); + assertThatThrownBy(() -> underTest.getDashboardUrl()) + .isInstanceOf(IllegalStateException.class); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index 5833168be7e..eb41915b0e2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -28,7 +28,6 @@ import java.nio.file.Path; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.sonar.api.batch.bootstrap.ProjectDefinition; @@ -52,6 +51,7 @@ import org.sonarqube.ws.client.WsResponse; import static org.apache.commons.io.FileUtils.readFileToString; 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.argThat; import static org.mockito.Mockito.mock; @@ -68,9 +68,6 @@ public class ReportPublisherTest { @Rule public JUnitTempFolder reportTempFolder = new JUnitTempFolder(); - @Rule - public ExpectedException exception = ExpectedException.none(); - private GlobalAnalysisMode mode = mock(GlobalAnalysisMode.class); private ScanProperties properties = mock(ScanProperties.class); private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class, Mockito.RETURNS_DEEP_STUBS); @@ -103,7 +100,7 @@ public class ReportPublisherTest { underTest.start(); underTest.execute(); - + verify(wsClient).call(argThat(req -> req.getWriteTimeOutInMs().orElse(0) == 30_000)); } @@ -127,9 +124,9 @@ public class ReportPublisherTest { when(response.failIfNotSuccessful()).thenThrow(ex); when(wsClient.call(any(WsRequest.class))).thenThrow(new IllegalStateException("timeout")); - exception.expect(IllegalStateException.class); - exception.expectMessage("Failed to upload report: timeout"); - underTest.upload(reportTempFolder.newFile()); + assertThatThrownBy(() -> underTest.upload(reportTempFolder.newFile())) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Failed to upload report: timeout"); } @Test @@ -139,9 +136,9 @@ public class ReportPublisherTest { when(response.failIfNotSuccessful()).thenThrow(ex); when(wsClient.call(any(WsRequest.class))).thenReturn(response); - exception.expect(MessageException.class); - exception.expectMessage("Server failed to process report. Please check server logs: Organization with key 'MyOrg' does not exist"); - underTest.upload(reportTempFolder.newFile()); + assertThatThrownBy(() -> underTest.upload(reportTempFolder.newFile())) + .isInstanceOf(MessageException.class) + .hasMessage("Server failed to process report. Please check server logs: Organization with key 'MyOrg' does not exist"); } @Test @@ -203,9 +200,9 @@ public class ReportPublisherTest { public void fail_if_public_url_malformed() { when(server.getPublicRootUrl()).thenReturn("invalid"); - exception.expect(MessageException.class); - exception.expectMessage("Failed to parse public URL set in SonarQube server: invalid"); - underTest.start(); + assertThatThrownBy(() -> underTest.start()) + .isInstanceOf(MessageException.class) + .hasMessage("Failed to parse public URL set in SonarQube server: invalid"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ContextPropertiesCacheTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ContextPropertiesCacheTest.java index 1db6afd6091..f54a561dfa6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ContextPropertiesCacheTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ContextPropertiesCacheTest.java @@ -19,18 +19,14 @@ */ package org.sonar.scanner.repository; -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.assertj.core.data.MapEntry.entry; public class ContextPropertiesCacheTest { - @Rule - public ExpectedException expectedException = ExpectedException.none(); - ContextPropertiesCache underTest = new ContextPropertiesCache(); @Test @@ -50,17 +46,15 @@ public class ContextPropertiesCacheTest { @Test public void put_throws_IAE_if_key_is_null() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Key of context property must not be null"); - - underTest.put(null, "bar"); + assertThatThrownBy(() -> underTest.put(null, "bar")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Key of context property must not be null"); } @Test public void put_throws_IAE_if_value_is_null() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("Value of context property must not be null"); - - underTest.put("foo", null); + assertThatThrownBy(() -> underTest.put("foo", null)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Value of context property must not be null"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultNewCodePeriodLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultNewCodePeriodLoaderTest.java index b02a5e19916..8c4eabb4a98 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultNewCodePeriodLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultNewCodePeriodLoaderTest.java @@ -23,9 +23,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.scanner.WsTestUtil; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; import org.sonarqube.ws.NewCodePeriods; @@ -33,8 +31,6 @@ import org.sonarqube.ws.NewCodePeriods; import static org.mockito.Mockito.mock; public class DefaultNewCodePeriodLoaderTest { - @Rule - public ExpectedException exception = ExpectedException.none(); private DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class); private DefaultNewCodePeriodLoader underTest = new DefaultNewCodePeriodLoader(wsClient); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java index 668b19b0176..f0170b7c1a6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java @@ -26,18 +26,17 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.utils.MessageException; import org.sonar.scanner.WsTestUtil; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; -import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonarqube.ws.Batch.WsProjectResponse; import org.sonarqube.ws.client.HttpException; import org.sonarqube.ws.client.WsRequest; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; @@ -45,8 +44,6 @@ import static org.mockito.Mockito.when; public class DefaultProjectRepositoriesLoaderTest { private final static String PROJECT_KEY = "foo?"; - @Rule - public ExpectedException thrown = ExpectedException.none(); private DefaultProjectRepositoriesLoader loader; private DefaultScannerWsClient wsClient; @@ -91,13 +88,13 @@ public class DefaultProjectRepositoriesLoaderTest { @Test public void failFastHttpErrorMessageException() { - thrown.expect(MessageException.class); - thrown.expectMessage("http error"); - HttpException http = new HttpException("uri", 403, null); MessageException e = MessageException.of("http error", http); WsTestUtil.mockException(wsClient, e); - loader.load(PROJECT_KEY, null); + + assertThatThrownBy(() -> loader.load(PROJECT_KEY, null)) + .isInstanceOf(MessageException.class) + .hasMessage("http error"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java index f85f94f27fc..008b7a29c69 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultQualityProfileLoaderTest.java @@ -23,9 +23,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.utils.MessageException; import org.sonar.scanner.WsTestUtil; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; @@ -34,12 +32,10 @@ import org.sonarqube.ws.Qualityprofiles; import org.sonarqube.ws.Qualityprofiles.SearchWsResponse.QualityProfile; import org.sonarqube.ws.client.HttpException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verifyNoMoreInteractions; public class DefaultQualityProfileLoaderTest { - @Rule - public ExpectedException exception = ExpectedException.none(); private final DefaultScannerWsClient wsClient = mock(DefaultScannerWsClient.class); private final ScanProperties properties = mock(ScanProperties.class); @@ -75,11 +71,9 @@ public class DefaultQualityProfileLoaderTest { public void load_throws_MessageException_if_no_profiles_are_available_for_specified_project() throws IOException { prepareCallWithEmptyResults(); - exception.expect(MessageException.class); - exception.expectMessage("No quality profiles"); - - underTest.load("project"); - verifyNoMoreInteractions(wsClient); + assertThatThrownBy(() -> underTest.load("project")) + .isInstanceOf(MessageException.class) + .hasMessageContaining("No quality profiles"); } private void verifyCalledPath(String expectedPath) { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesBuilderTest.java index 6f41f7b6e50..772a18afb52 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/ActiveRulesBuilderTest.java @@ -19,9 +19,7 @@ */ package org.sonar.scanner.rule; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; @@ -30,10 +28,9 @@ import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.Severity; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class ActiveRulesBuilderTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); @Test public void no_rules() { @@ -98,9 +95,8 @@ public class ActiveRulesBuilderTest { .build(); builder.addRule(rule); - thrown.expect(IllegalStateException.class); - thrown.expectMessage("Rule 'squid:S0001' is already activated"); - - builder.addRule(rule); + assertThatThrownBy(() -> builder.addRule(rule)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Rule 'squid:S0001' is already activated"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java index ba1f0401a5c..bd585b6a4b6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/DefaultRulesLoaderTest.java @@ -25,17 +25,15 @@ import java.io.IOException; import java.io.InputStream; import java.util.List; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.scanner.WsTestUtil; import org.sonar.scanner.bootstrap.DefaultScannerWsClient; import org.sonarqube.ws.Rules.ListResponse.Rule; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; public class DefaultRulesLoaderTest { - @org.junit.Rule - public ExpectedException exception = ExpectedException.none(); @Test public void testParseServerResponse() throws IOException { @@ -54,9 +52,8 @@ public class DefaultRulesLoaderTest { WsTestUtil.mockStream(wsClient, is); DefaultRulesLoader loader = new DefaultRulesLoader(wsClient); - exception.expect(IllegalStateException.class); - exception.expectMessage("Unable to get rules"); - - loader.load(); + assertThatThrownBy(() -> loader.load()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Unable to get rules"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java index 769fa3121e4..cb44b5af28c 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/rule/QProfileVerifierTest.java @@ -20,9 +20,7 @@ package org.sonar.scanner.rule; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.slf4j.Logger; import org.sonar.api.SonarRuntime; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; @@ -35,8 +33,6 @@ import static org.mockito.Mockito.when; public class QProfileVerifierTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); private InputComponentStore store; private QualityProfiles profiles; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DirectoryLockTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DirectoryLockTest.java index 930c63c2b14..930c269efde 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DirectoryLockTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/DirectoryLockTest.java @@ -23,16 +23,14 @@ import java.nio.file.Paths; 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; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class DirectoryLockTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); private DirectoryLock lock; @Before @@ -57,9 +55,8 @@ public class DirectoryLockTest { public void errorTryLock() { lock = new DirectoryLock(Paths.get("non", "existing", "path")); - expectedException.expect(IllegalStateException.class); - expectedException.expectMessage("Failed to create lock"); - - lock.tryLock(); + assertThatThrownBy(() -> lock.tryLock()) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("Failed to create lock"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java index 2e2dca0ce46..a5e0dd2ffd9 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectBuildersExecutorTest.java @@ -20,15 +20,14 @@ package org.sonar.scanner.scan; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.batch.bootstrap.ProjectBuilder; import org.sonar.api.batch.bootstrap.ProjectBuilder.Context; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.utils.MessageException; import org.sonar.scanner.bootstrap.GlobalConfiguration; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -36,9 +35,6 @@ import static org.mockito.Mockito.mock; public class ProjectBuildersExecutorTest { private ProjectReactor reactor; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Before public void setUp() { reactor = mock(ProjectReactor.class); @@ -50,9 +46,9 @@ public class ProjectBuildersExecutorTest { doThrow(new IllegalStateException()).when(builder).build(any(Context.class)); ProjectBuilder[] projectBuilders = {builder}; - exception.expectMessage("Failed to execute project builder: Mock for ProjectBuilder"); - exception.expect(MessageException.class); - new ProjectBuildersExecutor(mock(GlobalConfiguration.class), projectBuilders).execute(reactor); + assertThatThrownBy(() -> new ProjectBuildersExecutor(mock(GlobalConfiguration.class), projectBuilders).execute(reactor)) + .isInstanceOf(MessageException.class) + .hasMessageContaining("Failed to execute project builder: Mock for ProjectBuilder"); } @Test @@ -60,9 +56,9 @@ public class ProjectBuildersExecutorTest { ProjectBuilder[] projectBuilders = {new MyProjectBuilder()}; - exception.expectMessage("Failed to execute project builder: org.sonar.scanner.scan.ProjectBuildersExecutorTest$MyProjectBuilder"); - exception.expect(MessageException.class); - new ProjectBuildersExecutor(mock(GlobalConfiguration.class), projectBuilders).execute(reactor); + assertThatThrownBy(() -> new ProjectBuildersExecutor(mock(GlobalConfiguration.class), projectBuilders).execute(reactor)) + .isInstanceOf(MessageException.class) + .hasMessage("Failed to execute project builder: org.sonar.scanner.scan.ProjectBuildersExecutorTest$MyProjectBuilder"); } static class MyProjectBuilder extends ProjectBuilder { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java index 5c2dc66fd8f..00cf9f490dd 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectLockTest.java @@ -26,19 +26,17 @@ import java.nio.file.Path; 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.bootstrap.ProjectDefinition; import org.sonar.api.batch.fs.internal.DefaultInputProject; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class ProjectLockTest { @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); - @Rule - public ExpectedException exception = ExpectedException.none(); private ProjectLock lock; private File baseDir; private File worDir; @@ -63,10 +61,11 @@ public class ProjectLockTest { @Test public void tryLockConcurrently() { - exception.expect(IllegalStateException.class); - exception.expectMessage("Another SonarQube analysis is already in progress for this project"); - lock.tryLock(); lock.tryLock(); + + assertThatThrownBy(() -> lock.tryLock()) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Another SonarQube analysis is already in progress for this project"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java index 5f699f6828f..70b698132d0 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ProjectReactorBuilderTest.java @@ -31,7 +31,6 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.batch.bootstrap.ProjectDefinition; import org.sonar.api.batch.bootstrap.ProjectReactor; import org.sonar.api.notifications.AnalysisWarnings; @@ -42,14 +41,12 @@ import org.sonar.scanner.bootstrap.ScannerProperties; import static java.util.Collections.emptyMap; import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; public class ProjectReactorBuilderTest { @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); @Test @@ -65,11 +62,10 @@ public class ProjectReactorBuilderTest { @Test public void should_fail_if_sources_are_missing_in_leaf_module() { - thrown.expect(MessageException.class); - thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = " - + getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")"); - - loadProjectDefinition("simple-project-with-unexisting-source-dir"); + assertThatThrownBy(() -> loadProjectDefinition("simple-project-with-unexisting-source-dir")) + .isInstanceOf(MessageException.class) + .hasMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project' (base directory = " + + getResource(this.getClass(), "simple-project-with-unexisting-source-dir") + ")"); } @Test @@ -84,18 +80,16 @@ public class ProjectReactorBuilderTest { @Test public void modulesDuplicateIds() { - thrown.expect(MessageException.class); - thrown.expectMessage("Two modules have the same id: 'module1'. Each module must have a unique id."); - - loadProjectDefinition("multi-module-duplicate-id"); + assertThatThrownBy(() -> loadProjectDefinition("multi-module-duplicate-id")) + .isInstanceOf(MessageException.class) + .hasMessage("Two modules have the same id: 'module1'. Each module must have a unique id."); } @Test public void sonarModuleIdIsForbidden() { - thrown.expect(MessageException.class); - thrown.expectMessage("'sonar' is not a valid module id. Please check property 'sonar.modules'."); - - loadProjectDefinition("multi-module-sonar-module"); + assertThatThrownBy(() -> loadProjectDefinition("multi-module-sonar-module")) + .isInstanceOf(MessageException.class) + .hasMessage("'sonar' is not a valid module id. Please check property 'sonar.modules'."); } @Test @@ -243,38 +237,34 @@ public class ProjectReactorBuilderTest { @Test public void shouldFailIfUnexistingModuleBaseDir() { - thrown.expect(MessageException.class); - thrown.expectMessage("The base directory of the module 'module1' does not exist: " - + getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1"); - - loadProjectDefinition("multi-module-with-unexisting-basedir"); + assertThatThrownBy(() -> loadProjectDefinition("multi-module-with-unexisting-basedir")) + .isInstanceOf(MessageException.class) + .hasMessage("The base directory of the module 'module1' does not exist: " + + getResource(this.getClass(), "multi-module-with-unexisting-basedir").getAbsolutePath() + File.separator + "module1"); } @Test public void shouldFailIfUnexistingSourceFolderInheritedInMultimodule() { - thrown.expect(MessageException.class); - thrown.expectMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project:module1' (base directory = " - + getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)"); - - loadProjectDefinition("multi-module-with-unexisting-source-dir"); + assertThatThrownBy(() -> loadProjectDefinition("multi-module-with-unexisting-source-dir")) + .isInstanceOf(MessageException.class) + .hasMessage("The folder 'unexisting-source-dir' does not exist for 'com.foo.project:module1' (base directory = " + + getResource(this.getClass(), "multi-module-with-unexisting-source-dir").getAbsolutePath() + File.separator + "module1)"); } @Test public void shouldFailIfExplicitUnexistingTestFolder() { - thrown.expect(MessageException.class); - thrown.expectMessage("The folder 'tests' does not exist for 'com.foo.project' (base directory = " - + getResource(this.getClass(), "simple-project-with-unexisting-test-dir").getAbsolutePath()); - - loadProjectDefinition("simple-project-with-unexisting-test-dir"); + assertThatThrownBy(() -> loadProjectDefinition("simple-project-with-unexisting-test-dir")) + .isInstanceOf(MessageException.class) + .hasMessageContaining("The folder 'tests' does not exist for 'com.foo.project' (base directory = " + + getResource(this.getClass(), "simple-project-with-unexisting-test-dir").getAbsolutePath()); } @Test public void shouldFailIfExplicitUnexistingTestFolderOnModule() { - thrown.expect(MessageException.class); - thrown.expectMessage("The folder 'tests' does not exist for 'module1' (base directory = " - + getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)"); - - loadProjectDefinition("multi-module-with-explicit-unexisting-test-dir"); + assertThatThrownBy(() -> loadProjectDefinition("multi-module-with-explicit-unexisting-test-dir")) + .isInstanceOf(MessageException.class) + .hasMessage("The folder 'tests' does not exist for 'module1' (base directory = " + + getResource(this.getClass(), "multi-module-with-explicit-unexisting-test-dir").getAbsolutePath() + File.separator + "module1)"); } @Test @@ -318,10 +308,9 @@ public class ProjectReactorBuilderTest { props.put("foo1", "bla"); props.put("foo4", "bla"); - thrown.expect(MessageException.class); - thrown.expectMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3"); - - ProjectReactorBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"}); + assertThatThrownBy(() -> ProjectReactorBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"})) + .isInstanceOf(MessageException.class) + .hasMessage("You must define the following mandatory properties for 'Unknown': foo2, foo3"); } @Test @@ -330,10 +319,9 @@ public class ProjectReactorBuilderTest { props.put("foo1", "bla"); props.put("sonar.projectKey", "my-project"); - thrown.expect(MessageException.class); - thrown.expectMessage("You must define the following mandatory properties for 'my-project': foo2, foo3"); - - ProjectReactorBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"}); + assertThatThrownBy(() -> ProjectReactorBuilder.checkMandatoryProperties(props, new String[] {"foo1", "foo2", "foo3"})) + .isInstanceOf(MessageException.class) + .hasMessage("You must define the following mandatory properties for 'my-project': foo2, foo3"); } @Test @@ -439,10 +427,9 @@ public class ProjectReactorBuilderTest { // Now, add it and check again root.addSubProject(mod2); - thrown.expect(MessageException.class); - thrown.expectMessage("Project 'root' can't have 2 modules with the following key: mod2"); - - ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root); + assertThatThrownBy(() -> ProjectReactorBuilder.checkUniquenessOfChildKey(mod2, root)) + .isInstanceOf(MessageException.class) + .hasMessage("Project 'root' can't have 2 modules with the following key: mod2"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java index 8e0726d64e8..02eed8c611d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/ScanPropertiesTest.java @@ -25,13 +25,13 @@ import java.util.Optional; 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.internal.DefaultInputProject; import org.sonar.api.config.internal.MapSettings; import org.sonar.api.utils.MessageException; 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; @@ -43,9 +43,6 @@ public class ScanPropertiesTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException exception = ExpectedException.none(); - @Before public void setUp() throws IOException { when(project.getBaseDir()).thenReturn(temp.newFolder().toPath()); @@ -90,9 +87,8 @@ public class ScanPropertiesTest { public void validate_fails_if_metadata_file_location_is_not_absolute() { settings.setProperty("sonar.scanner.metadataFilePath", "relative"); - exception.expect(MessageException.class); - exception.expectMessage("Property 'sonar.scanner.metadataFilePath' must point to an absolute path: relative"); - underTest.validate(); - + assertThatThrownBy(() -> underTest.validate()) + .isInstanceOf(MessageException.class) + .hasMessage("Property 'sonar.scanner.metadataFilePath' must point to an absolute path: relative"); } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java index 4c57b96de04..c7ad4010ebc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/CharsetDetectorTest.java @@ -32,7 +32,6 @@ import org.apache.commons.io.IOUtils; import org.apache.commons.lang.StringUtils; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import static java.nio.charset.StandardCharsets.US_ASCII; @@ -41,14 +40,12 @@ import static java.nio.charset.StandardCharsets.UTF_16BE; import static java.nio.charset.StandardCharsets.UTF_16LE; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class CharsetDetectorTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void should_detect_charset_from_BOM() { Path basedir = Paths.get("src/test/resources/org/sonar/scanner/scan/filesystem/"); @@ -75,7 +72,7 @@ public class CharsetDetectorTest { @Test public void always_try_utf8() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); - // this is a valid 2 byte UTF-8. + // this is a valid 2 byte UTF-8. out.write(194); out.write(128); @@ -86,9 +83,9 @@ public class CharsetDetectorTest { @Test public void fail_if_file_doesnt_exist() { - exception.expect(IllegalStateException.class); - exception.expectMessage("Unable to read file " + Paths.get("non_existing").toAbsolutePath()); - detectCharset(Paths.get("non_existing"), UTF_8); + assertThatThrownBy(() -> detectCharset(Paths.get("non_existing"), UTF_8)) + .isInstanceOf(IllegalStateException.class) + .hasMessage("Unable to read file " + Paths.get("non_existing").toAbsolutePath()); } @Test @@ -98,16 +95,16 @@ public class CharsetDetectorTest { new Random().nextBytes(b); // avoid accidental BOM matching b[0] = 1; - + // avoid UTF-8 / UTF-16 b[100] = 0; b[101] = 0; b[102] = 0; b[103] = 0; - + // invalid in win-1258 b[200] = (byte) 129; - + Files.write(filePath, b); CharsetDetector detector = new CharsetDetector(filePath, UTF_8); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java index 878826c186d..fc141f30ff7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/filesystem/LanguageDetectionTest.java @@ -24,7 +24,6 @@ import java.nio.file.Paths; 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.config.internal.MapSettings; import org.sonar.api.resources.Language; @@ -42,8 +41,6 @@ public class LanguageDetectionTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); private MapSettings settings; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java index 56a157ac369..dce0ef0a204 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java @@ -20,9 +20,7 @@ package org.sonar.scanner.scm; import java.util.Date; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.scm.BlameLine; @@ -32,13 +30,12 @@ import org.sonar.scanner.notifications.DefaultAnalysisWarnings; import static java.util.Collections.singletonList; 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 DefaultBlameOutputTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); private System2 system2 = mock(System2.class); private DefaultAnalysisWarnings analysisWarnings = new DefaultAnalysisWarnings(system2); private ScannerWsClient client = mock(ScannerWsClient.class); @@ -64,33 +61,30 @@ public class DefaultBlameOutputTest { public void shouldFailIfNotExpectedFile() { InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").build(); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("It was not expected to blame file " + file); - - new DefaultBlameOutput(null, analysisWarnings, singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()), client) - .blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))); + assertThatThrownBy(() -> new DefaultBlameOutput(null, analysisWarnings, + singletonList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()), client) + .blameResult(file, singletonList(new BlameLine().revision("1").author("guy")))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("It was not expected to blame file " + file); } @Test public void shouldFailIfNullDate() { InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build(); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Blame date is null for file " + file + " at line 1"); - - new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client) - .blameResult(file, singletonList(new BlameLine().revision("1").author("guy"))); + assertThatThrownBy(() -> new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client) + .blameResult(file, singletonList(new BlameLine().revision("1").author("guy")))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Blame date is null for file " + file + " at line 1"); } @Test public void shouldFailIfNullRevision() { InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build(); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Blame revision is blank for file " + file + " at line 1"); - - new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client) - .blameResult(file, singletonList(new BlameLine().date(new Date()).author("guy"))); + assertThatThrownBy(() -> new DefaultBlameOutput(null, analysisWarnings, singletonList(file), client) + .blameResult(file, singletonList(new BlameLine().date(new Date()).author("guy")))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Blame revision is blank for file " + file + " at line 1"); } - } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java index 89ac179595d..6d574bfdc9e 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesProviderTest.java @@ -23,17 +23,16 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.sonar.api.batch.scm.ScmProvider; import org.sonar.api.batch.fs.internal.DefaultInputProject; +import org.sonar.api.batch.scm.ScmProvider; import org.sonar.scanner.fs.InputModuleHierarchy; import org.sonar.scanner.scan.branch.BranchConfiguration; 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.verifyZeroInteractions; @@ -49,9 +48,6 @@ public class ScmChangedFilesProviderTest { @Mock private ScmProvider scmProvider; - @Rule - public ExpectedException exception = ExpectedException.none(); - private Path rootBaseDir = Paths.get("root"); private ScmChangedFilesProvider provider; private DefaultInputProject project = mock(DefaultInputProject.class); @@ -81,9 +77,9 @@ public class ScmChangedFilesProviderTest { when(scmConfiguration.provider()).thenReturn(scmProvider); when(scmProvider.branchChangedFiles("target", rootBaseDir)).thenReturn(Collections.singleton(Paths.get("changedFile"))); - exception.expect(IllegalStateException.class); - exception.expectMessage("changed file with a relative path"); - provider.provide(scmConfiguration, branchConfiguration, project); + assertThatThrownBy(() -> provider.provide(scmConfiguration, branchConfiguration, project)) + .isInstanceOf(IllegalStateException.class) + .hasMessageContaining("changed file with a relative path"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java index d764e263f37..f0e3b0f3c92 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmChangedFilesTest.java @@ -23,18 +23,14 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collection; import java.util.Collections; -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 ScmChangedFilesTest { private ScmChangedFiles scmChangedFiles; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testGetter() { Collection<Path> files = Collections.singletonList(Paths.get("files")); @@ -48,8 +44,8 @@ public class ScmChangedFilesTest { assertThat(scmChangedFiles.isValid()).isFalse(); assertThat(scmChangedFiles.get()).isNull(); - exception.expect(IllegalStateException.class); - assertThat(scmChangedFiles.isChanged(Paths.get("files2"))).isTrue(); + assertThatThrownBy(() -> scmChangedFiles.isChanged(Paths.get("files2"))) + .isInstanceOf(IllegalStateException.class); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java index 70dcfe524ee..f72050c6ac6 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/ScmConfigurationTest.java @@ -23,11 +23,8 @@ import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; import com.tngtech.java.junit.dataprovider.UseDataProvider; import java.util.Optional; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.Answers; import org.sonar.api.CoreProperties; @@ -40,6 +37,7 @@ import org.sonar.core.config.ScannerProperties; import org.sonar.scanner.fs.InputModuleHierarchy; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; @@ -65,9 +63,6 @@ public class ScmConfigurationTest { @Rule public LogTester logTester = new LogTester(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - public ScmConfigurationTest() { when(scmProvider.key()).thenReturn(scmProviderKey); @@ -146,33 +141,20 @@ public class ScmConfigurationTest { ScmProvider[] providers = {scmProvider, scmProvider}; ScmConfiguration underTest = new ScmConfiguration(inputModuleHierarchy, settings, analysisWarnings, providers); - thrown.expect(MessageException.class); - thrown.expectMessage( - new BaseMatcher<String>() { - @Override - public void describeTo(Description description) { - - } - - @Override - public boolean matches(Object item) { - return ((String) item).matches("SCM provider autodetection failed. " - + "Both .* and .* claim to support this project. " - + "Please use \"sonar.scm.provider\" to define SCM of your project."); - } - }); - - underTest.start(); + assertThatThrownBy(() -> underTest.start()) + .isInstanceOf(MessageException.class) + .hasMessageContaining("SCM provider autodetection failed. " + + "Both key2 and key2 claim to support this project. " + + "Please use \"sonar.scm.provider\" to define SCM of your project."); } @Test public void fail_when_considerOldScmUrl_finds_invalid_provider_in_link() { when(settings.get(ScannerProperties.LINKS_SOURCES_DEV)).thenReturn(Optional.of("scm:invalid")); - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("no SCM provider found for this key"); - - underTest.start(); + assertThatThrownBy(() -> underTest.start()) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("no SCM provider found for this key"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java index 96b1b58dccb..6e8dcdde475 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/DefaultSensorStorageTest.java @@ -26,7 +26,6 @@ import java.util.List; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.mockito.ArgumentCaptor; import org.sonar.api.batch.bootstrap.ProjectDefinition; @@ -62,6 +61,7 @@ import org.sonar.scanner.repository.ContextPropertiesCache; import org.sonar.scanner.scan.branch.BranchConfiguration; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.data.MapEntry.entry; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -74,9 +74,6 @@ public class DefaultSensorStorageTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private DefaultSensorStorage underTest; private MapSettings settings; private IssuePublisher moduleIssues; @@ -141,13 +138,12 @@ public class DefaultSensorStorageTest { public void shouldFailIfUnknownMetric() { InputFile file = new TestInputFileBuilder("foo", "src/Foo.php").build(); - thrown.expect(UnsupportedOperationException.class); - thrown.expectMessage("Unknown metric: lines"); - - underTest.store(new DefaultMeasure() + assertThatThrownBy(() -> underTest.store(new DefaultMeasure() .on(file) .forMetric(CoreMetrics.LINES) - .withValue(10)); + .withValue(10))) + .isInstanceOf(UnsupportedOperationException.class) + .hasMessage("Unknown metric: lines"); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java index 1073e608348..485a757642d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorContextTest.java @@ -22,22 +22,21 @@ package org.sonar.scanner.sensor; 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.SonarEdition; import org.sonar.api.SonarQubeSide; import org.sonar.api.SonarRuntime; import org.sonar.api.batch.fs.InputModule; +import org.sonar.api.batch.fs.internal.DefaultFileSystem; +import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.batch.measure.MetricFinder; import org.sonar.api.batch.rule.ActiveRules; +import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import org.sonar.api.batch.sensor.internal.SensorStorage; import org.sonar.api.config.internal.MapSettings; -import org.sonar.api.batch.fs.internal.DefaultFileSystem; -import org.sonar.api.batch.fs.internal.DefaultInputProject; import org.sonar.api.internal.SonarRuntimeImpl; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.utils.Version; -import org.sonar.api.batch.rule.internal.ActiveRulesBuilder; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -48,9 +47,6 @@ public class ModuleSensorContextTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private ActiveRules activeRules; private DefaultFileSystem fs; private ModuleSensorContext adaptor; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java index f0054ef1546..fbf011e8ccc 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/sensor/ModuleSensorOptimizerTest.java @@ -22,7 +22,6 @@ package org.sonar.scanner.sensor; 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.DefaultFileSystem; @@ -41,9 +40,6 @@ public class ModuleSensorOptimizerTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private DefaultFileSystem fs; private ModuleSensorOptimizer optimizer; private MapSettings settings; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java index bfd900b328a..649fb3c8d31 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java @@ -21,15 +21,12 @@ package org.sonar.scm.git; import java.io.IOException; import java.io.OutputStreamWriter; -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 ChangedLinesComputerTest { - @Rule - public ExpectedException exception = ExpectedException.none(); private final ChangedLinesComputer underTest = new ChangedLinesComputer(); @Test @@ -142,8 +139,8 @@ public class ChangedLinesComputerTest { + "+added line 1\n" + "+added line 2\n"; - exception.expect(IllegalStateException.class); - printDiff(example); + assertThatThrownBy(() -> printDiff(example)) + .isInstanceOf(IllegalStateException.class); } private void printDiff(String unifiedDiff) throws IOException { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java index 96226264aa7..a98137a80f2 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java @@ -53,7 +53,6 @@ import org.eclipse.jgit.treewalk.AbstractTreeIterator; 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.notifications.AnalysisWarnings; import org.sonar.api.scan.filesystem.PathResolver; @@ -65,6 +64,7 @@ import org.sonar.scanner.bootstrap.ScannerWsClient; import static java.util.Collections.emptySet; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.data.MapEntry.entry; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -113,9 +113,6 @@ public class GitScmProviderTest { @Rule public LogTester logs = new LogTester(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private final GitIgnoreCommand gitIgnoreCommand = mock(GitIgnoreCommand.class); private static final Random random = new Random(); private static final System2 system2 = mock(System2.class); @@ -616,16 +613,16 @@ public class GitScmProviderTest { @Test public void branchChangedFiles_should_throw_when_repo_nonexistent() throws IOException { - thrown.expect(MessageException.class); - thrown.expectMessage("Not inside a Git work tree: "); - newScmProvider().branchChangedFiles("master", temp.newFolder().toPath()); + assertThatThrownBy(() -> newScmProvider().branchChangedFiles("master", temp.newFolder().toPath())) + .isInstanceOf(MessageException.class) + .hasMessageContaining("Not inside a Git work tree: "); } @Test public void branchChangedFiles_should_throw_when_dir_nonexistent() { - thrown.expect(MessageException.class); - thrown.expectMessage("Not inside a Git work tree: "); - newScmProvider().branchChangedFiles("master", temp.getRoot().toPath().resolve("nonexistent")); + assertThatThrownBy(() -> newScmProvider().branchChangedFiles("master", temp.getRoot().toPath().resolve("nonexistent"))) + .isInstanceOf(MessageException.class) + .hasMessageContaining("Not inside a Git work tree: "); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java index 7af6d32e63e..020cae0e362 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/JGitBlameCommandTest.java @@ -33,7 +33,6 @@ import java.util.Map; import org.apache.commons.io.FileUtils; 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.DefaultFileSystem; @@ -50,6 +49,7 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.log.LogTester; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assume.assumeTrue; import static org.mockito.Matchers.startsWith; import static org.mockito.Mockito.mock; @@ -63,9 +63,6 @@ public class JGitBlameCommandTest { private static final String DUMMY_JAVA = "src/main/java/org/dummy/Dummy.java"; @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public TemporaryFolder temp = new TemporaryFolder(); @Rule @@ -135,10 +132,9 @@ public class JGitBlameCommandTest { BlameOutput blameResult = mock(BlameOutput.class); when(input.filesToBlame()).thenReturn(Arrays.asList(inputFile)); - thrown.expect(MessageException.class); - thrown.expectMessage("Not inside a Git work tree: "); - - jGitBlameCommand.blame(input, blameResult); + assertThatThrownBy(() -> jGitBlameCommand.blame(input, blameResult)) + .isInstanceOf(MessageException.class) + .hasMessageContaining("Not inside a Git work tree: "); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnBlameCommandTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnBlameCommandTest.java index 2e14e099827..c8b70534f06 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnBlameCommandTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnBlameCommandTest.java @@ -36,7 +36,6 @@ import java.util.zip.ZipFile; import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -93,9 +92,6 @@ public class SvnBlameCommandTest { public TemporaryFolder temp = new TemporaryFolder(); @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule public LogTester logTester = new LogTester(); private FileSystem fs; diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java index 1f28f21c91d..ae10963a47d 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java @@ -34,7 +34,6 @@ import java.util.Set; 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.ScmProvider; import org.tmatesoft.svn.core.SVNCancelException; @@ -83,9 +82,6 @@ public class SvnScmProviderTest { @Rule public TemporaryFolder temp = new TemporaryFolder(); - @Rule - public ExpectedException thrown = ExpectedException.none(); - private FindFork findFork = mock(FindFork.class); private SvnConfiguration config = mock(SvnConfiguration.class); private SvnTester svnTester; |