diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-29 16:57:20 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-29 16:57:30 +0200 |
commit | 64b43e759608ba4bec30be11dc9c6a0feed6fc8e (patch) | |
tree | fbd4204bbcc93b9251ae28f1bed1ad3933a06ad8 | |
parent | b47468faac1dbfb669d4bca8b22edbc81796a85f (diff) | |
download | sonarqube-64b43e759608ba4bec30be11dc9c6a0feed6fc8e.tar.gz sonarqube-64b43e759608ba4bec30be11dc9c6a0feed6fc8e.zip |
Try to increase stability of HttpDownloaderTest
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java index 506977ab431..5dcd2f2b937 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/HttpDownloaderTest.java @@ -28,6 +28,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.rules.TemporaryFolder; +import org.junit.rules.Timeout; import org.simpleframework.http.Request; import org.simpleframework.http.Response; import org.simpleframework.http.core.Container; @@ -57,6 +58,9 @@ import static org.mockito.Mockito.when; public class HttpDownloaderTest { @Rule + public Timeout timeout = new Timeout(1000); + + @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Rule @@ -135,13 +139,13 @@ public class HttpDownloaderTest { assertThat(text).isEqualTo("GZIP response"); } - @Test(timeout = 1000L) + @Test public void readStringWithDefaultTimeout() throws URISyntaxException { String text = new HttpDownloader(new Settings()).readString(new URI(baseUrl + "/timeout/"), Charsets.UTF_8); assertThat(text.length()).isGreaterThan(10); } - @Test(timeout = 1000L) + @Test public void readStringWithTimeout() throws URISyntaxException { thrown.expect(new BaseMatcher<Exception>() { @Override @@ -156,13 +160,13 @@ public class HttpDownloaderTest { new HttpDownloader(new Settings(), 50).readString(new URI(baseUrl + "/timeout/"), Charsets.UTF_8); } - @Test(expected = SonarException.class, timeout = 1000L) - public void failIfServerDown() throws URISyntaxException { - // I hope that the port 1 is not used ! - new HttpDownloader(new Settings()).readBytes(new URI("http://localhost:1/unknown")); + @Test(expected = SonarException.class) + public void failIfServerDown() throws Exception { + int port = new InetSocketAddress(0).getPort(); + new HttpDownloader(new Settings()).readBytes(new URI("http://localhost:" + port)); } - @Test(timeout = 1000L) + @Test public void downloadToFile() throws URISyntaxException, IOException { File toDir = temporaryFolder.newFolder(); File toFile = new File(toDir, "downloadToFile.txt"); |