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);
}
}
*/
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;
userRepo = new UserRepositoryLoader(wsLoader);
}
+ @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");
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;
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);
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);
+ }
+
}