aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch/src/test
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2011-04-19 11:55:28 +0200
committersimonbrandhof <simon.brandhof@gmail.com>2011-04-19 11:55:28 +0200
commit104854e399001150622b638e194d732048bbb914 (patch)
treeffac6ea507420bf4e65a41eb7bb4da7e458db49d /sonar-batch/src/test
parent6ed558af9f2367ad233e6924193c142bddaad1d0 (diff)
downloadsonarqube-104854e399001150622b638e194d732048bbb914.tar.gz
sonarqube-104854e399001150622b638e194d732048bbb914.zip
SONAR-2278 Improve exception handling of decorators
Diffstat (limited to 'sonar-batch/src/test')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java35
1 files changed, 31 insertions, 4 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
index 396ce2b4e36..fc86a6d4c27 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/phases/DecoratorsExecutorTest.java
@@ -19,15 +19,27 @@
*/
package org.sonar.batch.phases;
-import static org.hamcrest.number.OrderingComparisons.greaterThanOrEqualTo;
-import static org.hamcrest.number.OrderingComparisons.lessThan;
-import static org.junit.Assert.assertThat;
-
import org.junit.Test;
+import org.sonar.api.batch.BatchExtensionDictionnary;
import org.sonar.api.batch.Decorator;
import org.sonar.api.batch.DecoratorContext;
+import org.sonar.api.batch.SonarIndex;
+import org.sonar.api.resources.File;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
+import org.sonar.api.utils.SonarException;
+import org.sonar.batch.DefaultDecoratorContext;
+import org.sonar.batch.events.EventBus;
+
+import static org.hamcrest.number.OrderingComparisons.greaterThanOrEqualTo;
+import static org.hamcrest.number.OrderingComparisons.lessThan;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+import static org.junit.matchers.JUnitMatchers.containsString;
+import static org.mockito.Matchers.any;
+
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
public class DecoratorsExecutorTest {
@@ -49,6 +61,21 @@ public class DecoratorsExecutorTest {
assertThat(profiler.getMessage().indexOf("Decorator1"), lessThan(profiler.getMessage().indexOf("Decorator2")));
}
+ @Test
+ public void exceptionShouldIncludeResource() {
+ Decorator decorator = mock(Decorator.class);
+ doThrow(new SonarException()).when(decorator).decorate(any(Resource.class), any(DecoratorContext.class));
+
+ DecoratorsExecutor executor = new DecoratorsExecutor(mock(BatchExtensionDictionnary.class), mock(SonarIndex.class), mock(EventBus.class));
+ try {
+ executor.executeDecorator(decorator, mock(DefaultDecoratorContext.class), new File("org/foo/Bar.java"));
+ fail("Exception has not been thrown");
+
+ } catch (SonarException e) {
+ assertThat(e.getMessage(), containsString("org/foo/Bar.java"));
+ }
+ }
+
static class Decorator1 implements Decorator {
public void decorate(Resource resource, DecoratorContext context) {
}