From 9de5340fcdcd27c8840364b6194aa6e972616ad2 Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Fri, 9 Oct 2015 11:41:54 +0200 Subject: [PATCH] Improve coverage --- .../DefaultProjectRepositoriesLoader.java | 2 +- .../DefaultProjectRepositoriesLoaderTest.java | 29 ++++++++++++++++++ .../project.protobuf | Bin 0 -> 2246 bytes 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest/project.protobuf diff --git a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java index 6f4f10c74fa..11bf530e8b3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java +++ b/sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java @@ -113,7 +113,7 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad return new ProjectRepositories(settings, fileDataTable, new Date(response.getLastAnalysisDate())); } catch (IOException e) { - throw new IllegalStateException("Couldn't load project settings for " + projectKey, e); + throw new IllegalStateException("Couldn't load project repository for " + projectKey, e); } finally { IOUtils.closeQuietly(is); } diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java index 25a5fd2f171..2641fc2b536 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java @@ -19,6 +19,8 @@ */ package org.sonar.batch.repository; +import com.google.common.io.Resources; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -63,6 +65,15 @@ public class DefaultProjectRepositoriesLoaderTest { assertThat(proj.exists()).isEqualTo(false); } + @Test + public void parsingError() throws IOException { + InputStream is = mock(InputStream.class); + when(is.read()).thenThrow(IOException.class); + + when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult(is, false)); + loader.load(PROJECT_KEY, false, null); + } + @Test(expected = IllegalStateException.class) public void failFastHttpError() { HttpException http = new HttpException(URI.create("uri"), 403); @@ -102,4 +113,22 @@ public class DefaultProjectRepositoriesLoaderTest { return new ByteArrayInputStream(os.toByteArray()); } + @Test + public void readRealResponse() throws IOException { + InputStream is = getTestResource("project.protobuf"); + when(wsLoader.loadStream(anyString())).thenReturn(new WSLoaderResult(is, true)); + + ProjectRepositories proj = loader.load("org.sonarsource.github:sonar-github-plugin", true, null); + FileData fd = proj.fileData("org.sonarsource.github:sonar-github-plugin", + "src/test/java/org/sonar/plugins/github/PullRequestIssuePostJobTest.java"); + + assertThat(fd.revision()).isEqualTo("27bf2c54633d05c5df402bbe09471fe43bd9e2e5"); + assertThat(fd.hash()).isEqualTo("edb6b3b9ab92d8dc53ba90ab86cd422e"); + } + + private InputStream getTestResource(String name) throws IOException { + return Resources.asByteSource(this.getClass().getResource(this.getClass().getSimpleName() + "/" + name)) + .openBufferedStream(); + } + } diff --git a/sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest/project.protobuf b/sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest/project.protobuf new file mode 100644 index 0000000000000000000000000000000000000000..ce579fdbd5e2412eed867e1311b7ba8417db52c0 GIT binary patch literal 2246 zcmcJQO^zc)5QV87s@-_WYL?bW-HyzR{2PG;G&4;jkXrm4ATl%3Q!~cZxT@d+Nc>A6 zgb+KeBF)D zru6vs*4f>~+0ABJciY7e58B_G_Hx+e)yTuRdQM-`O5R`H9$wv@8di5Nt*)od=41Y1 zl9N}%F!6Oij34yrQ@K9hzq$CZeaI!bWKyIQbqOU~lPChE;BrB&d9llH_gCC5@IESA|u1pz&wG6|!>#Flil z27|Zc0y{Q_ifg}X+IXZ$AJOi`d;M42&&F;u%+lx*DQH6DjdR+{cdH^J)cwt(>Inn; zwrRtWEH{*2(3;P>ZS7|i@1bfaArhc1UXX0Cz83a6S&uTMqrLN6(>^&8<fs6F`o3u&AIWvKy_v?R-G(nHKjRrDmsqoC zL%A5sq&;|&oY_PQT_L+zl41ZKDJO}XlmI|*jzDTctB@c8AZnuAo-nV=11rxcF?j8( zwn+!es0dLKl}e~ukyimu(B~x5)#?}YB<9gRW=RCeUb(_Nf zY325=kqRu{fz~E787Uc~bf#+czJ-pC+aFDPb);7R8@GF!1s7B?g^4OE5KIUPP-T)e zmZTd`VEd_Q-#XG-2b$f@arRa6(UL4KT~w05k(PxSa*~3oT8feuOG79t4P={eE|6>h zpE(d`@+mrEP*P?Z<4LJI*s?Qqq|r DB9g+$ literal 0 HcmV?d00001 -- 2.39.5