]> source.dussan.org Git - sonarqube.git/commitdiff
Improve coverage
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 9 Oct 2015 09:41:54 +0000 (11:41 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 9 Oct 2015 10:44:09 +0000 (12:44 +0200)
sonar-batch/src/main/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoader.java
sonar-batch/src/test/java/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest.java
sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest/project.protobuf [new file with mode: 0644]

index 6f4f10c74faa8889da80381b036f0637dfe7286c..11bf530e8b3167c42217a3ebd15c4d55998f2491 100644 (file)
@@ -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);
     }
index 25a5fd2f1716407c0af658140ef5de0af54b6292..2641fc2b5361992933a7f072cd02eeb39f7f30d8 100644 (file)
@@ -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<InputStream>(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<InputStream>(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 (file)
index 0000000..ce579fd
Binary files /dev/null and b/sonar-batch/src/test/resources/org/sonar/batch/repository/DefaultProjectRepositoriesLoaderTest/project.protobuf differ