aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2015-09-01 14:13:13 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2015-09-04 10:33:16 +0200
commitae4728b46e5b88b084bd0ae939b3c6bf5f81ed01 (patch)
treeb43a96af883793e7ca87b08a5758f7f5c9496d0a /sonar-batch
parent8b89d87b5e7a6e5bdb093b9220e83c63b2647ff2 (diff)
downloadsonarqube-ae4728b46e5b88b084bd0ae939b3c6bf5f81ed01.tar.gz
sonarqube-ae4728b46e5b88b084bd0ae939b3c6bf5f81ed01.zip
Improve batch unit tests
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java2
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java8
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java19
3 files changed, 26 insertions, 3 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
index 9d055b064c1..b427cfed871 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/rule/DefaultRulesLoader.java
@@ -57,7 +57,7 @@ public class DefaultRulesLoader implements RulesLoader {
try (InputStream is = input.openStream()) {
return ListResponse.parseFrom(is);
} catch (IOException e) {
- throw new IllegalStateException("Unable to get previous issues", e);
+ throw new IllegalStateException("Unable to get rules", e);
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
index c63bfda8d4c..5410f18a7c1 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/repository/user/UserRepositoryLoaderTest.java
@@ -19,8 +19,9 @@
*/
package org.sonar.batch.repository.user;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.assertj.core.util.Lists;
+import org.sonar.batch.cache.WSLoaderResult;
import org.sonar.batch.cache.WSLoader;
import org.junit.Before;
import com.google.common.collect.ImmutableList;
@@ -60,6 +61,11 @@ public class UserRepositoryLoaderTest {
}
@Test
+ public void testLoadEmptyList() {
+ assertThat(userRepo.load(Lists.<String>emptyList())).isEmpty();
+ }
+
+ @Test
public void testLoad() throws IOException {
Map<String, String> userMap = ImmutableMap.of("fmallet", "Freddy Mallet", "sbrandhof", "Simon");
WSLoaderResult<ByteSource> res = new WSLoaderResult<>(createUsersMock(userMap), true);
diff --git a/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java b/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
index 8995d3457b7..1c593a51361 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/rule/DefaultRulesLoaderTest.java
@@ -22,8 +22,9 @@ package org.sonar.batch.rule;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import org.sonar.batch.cache.WSLoaderResult;
+import org.junit.rules.ExpectedException;
+import org.sonar.batch.cache.WSLoaderResult;
import org.sonar.batch.cache.WSLoader;
import org.apache.commons.lang.mutable.MutableBoolean;
import org.sonarqube.ws.Rules.ListResponse.Rule;
@@ -38,6 +39,9 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class DefaultRulesLoaderTest {
+ @org.junit.Rule
+ public ExpectedException exception = ExpectedException.none();
+
@Test
public void testParseServerResponse() throws IOException {
WSLoader wsLoader = mock(WSLoader.class);
@@ -60,4 +64,17 @@ public class DefaultRulesLoaderTest {
assertThat(fromCache.booleanValue()).isTrue();
}
+ @Test
+ public void testError() {
+ WSLoader wsLoader = mock(WSLoader.class);
+ ByteSource source = ByteSource.wrap(new String("trash").getBytes());
+ when(wsLoader.loadSource(anyString())).thenReturn(new WSLoaderResult<>(source, true));
+ DefaultRulesLoader loader = new DefaultRulesLoader(wsLoader);
+
+ exception.expect(IllegalStateException.class);
+ exception.expectMessage("Unable to get rules");
+
+ loader.load(null);
+ }
+
}