aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-11-06 18:38:02 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2015-11-09 16:34:20 +0100
commit54efd097b74af0fccad20f19555652ce693d6020 (patch)
tree00d16f0d4a00ca0ee7916e909e05e37523732ade /sonar-batch
parent1d4bc6788cb482bb8b45e29f5bd4fca06c0e99f9 (diff)
downloadsonarqube-54efd097b74af0fccad20f19555652ce693d6020.tar.gz
sonarqube-54efd097b74af0fccad20f19555652ce693d6020.zip
SONAR-6990 add one missing UT on DuplicationsPublisher
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java
index b57c18df8e2..6482786f7dd 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/report/DuplicationsPublisherTest.java
@@ -22,9 +22,12 @@ package org.sonar.batch.report;
import java.io.File;
import java.util.Arrays;
import java.util.Collections;
+import org.hamcrest.Description;
+import org.hamcrest.TypeSafeMatcher;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DefaultInputModule;
@@ -37,6 +40,7 @@ import org.sonar.batch.protocol.output.BatchReport;
import org.sonar.batch.protocol.output.BatchReportReader;
import org.sonar.batch.protocol.output.BatchReportWriter;
import org.sonar.core.util.CloseableIterator;
+import org.sonar.core.util.ContextException;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
@@ -47,6 +51,8 @@ public class DuplicationsPublisherTest {
@Rule
public TemporaryFolder temp = new TemporaryFolder();
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
private DuplicationCache duplicationCache;
private DuplicationsPublisher publisher;
@@ -66,6 +72,48 @@ public class DuplicationsPublisherTest {
}
@Test
+ public void publishDuplications_throws_IAE_if_resource_of_duplicate_does_not_exist() throws Exception {
+
+ DefaultDuplication dup1 = new DefaultDuplication()
+ .setOriginBlock(new Duplication.Block("foo:src/Foo.php", 11, 10))
+ .isDuplicatedBy("another", 20, 50);
+ when(duplicationCache.byComponent("foo:src/Foo.php")).thenReturn(Arrays.asList(dup1));
+
+ expectedException.expect(ContextException.class);
+ expectedException.expectCause(new CauseMatcher(IllegalStateException.class, "No cross project duplication supported on batch side: another"));
+
+ File outputDir = temp.newFolder();
+ BatchReportWriter writer = new BatchReportWriter(outputDir);
+
+ publisher.publish(writer);
+ }
+
+ private static class CauseMatcher extends TypeSafeMatcher<Throwable> {
+
+ private final Class<? extends Throwable> type;
+ private final String expectedMessage;
+
+ public CauseMatcher(Class<? extends Throwable> type, String expectedMessage) {
+ this.type = type;
+ this.expectedMessage = expectedMessage;
+ }
+
+ @Override
+ protected boolean matchesSafely(Throwable item) {
+ return item.getClass().isAssignableFrom(type)
+ && item.getMessage().contains(expectedMessage);
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("expects type ")
+ .appendValue(type)
+ .appendText(" and a message ")
+ .appendValue(expectedMessage);
+ }
+ }
+
+ @Test
public void publishDuplications() throws Exception {
DefaultDuplication dup1 = new DefaultDuplication()