aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/sonar-xoo-plugin
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2014-09-01 09:56:47 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2014-09-01 09:56:59 +0200
commit629ca066726a98fcc9e068e9b854d23133eab715 (patch)
tree2e89acd6f27118fc5dbf3eb23205e38f58de7918 /plugins/sonar-xoo-plugin
parent28c9c5354566365afb1c865a30af1ce4e36075b0 (diff)
downloadsonarqube-629ca066726a98fcc9e068e9b854d23133eab715.tar.gz
sonarqube-629ca066726a98fcc9e068e9b854d23133eab715.zip
Improve code coverage
Diffstat (limited to 'plugins/sonar-xoo-plugin')
-rw-r--r--plugins/sonar-xoo-plugin/pom.xml5
-rw-r--r--plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java4
-rw-r--r--plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java74
3 files changed, 81 insertions, 2 deletions
diff --git a/plugins/sonar-xoo-plugin/pom.xml b/plugins/sonar-xoo-plugin/pom.xml
index 15955bbd380..6c1a1182306 100644
--- a/plugins/sonar-xoo-plugin/pom.xml
+++ b/plugins/sonar-xoo-plugin/pom.xml
@@ -36,6 +36,11 @@
<artifactId>sonar-testing-harness</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
index c8cafc2d705..628ce6ece70 100644
--- a/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
+++ b/plugins/sonar-xoo-plugin/src/main/java/org/sonar/xoo/lang/SymbolReferencesSensor.java
@@ -44,7 +44,7 @@ public class SymbolReferencesSensor implements Sensor {
private static final String SYMBOL_EXTENSION = ".symbol";
- private void processFileHighlighting(InputFile inputFile, SensorContext context) {
+ private void processFileSymbol(InputFile inputFile, SensorContext context) {
File ioFile = inputFile.file();
File symbolFile = new File(ioFile.getParentFile(), ioFile.getName() + SYMBOL_EXTENSION);
if (symbolFile.exists()) {
@@ -92,7 +92,7 @@ public class SymbolReferencesSensor implements Sensor {
@Override
public void execute(SensorContext context) {
for (InputFile file : context.fileSystem().inputFiles(context.fileSystem().predicates().hasLanguages(Xoo.KEY))) {
- processFileHighlighting(file, context);
+ processFileSymbol(file, context);
}
}
}
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
new file mode 100644
index 00000000000..3c01302baac
--- /dev/null
+++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SymbolReferencesSensorTest.java
@@ -0,0 +1,74 @@
+package org.sonar.xoo.lang;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.sonar.api.batch.fs.internal.DefaultFileSystem;
+import org.sonar.api.batch.fs.internal.DefaultInputFile;
+import org.sonar.api.batch.sensor.SensorContext;
+import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;
+import org.sonar.api.batch.sensor.symbol.Symbol;
+import org.sonar.api.batch.sensor.symbol.SymbolTableBuilder;
+
+import java.io.File;
+import java.io.IOException;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+public class SymbolReferencesSensorTest {
+
+ private SymbolReferencesSensor sensor;
+ private SensorContext context = mock(SensorContext.class);
+ private DefaultFileSystem fileSystem;
+
+ @Rule
+ public TemporaryFolder temp = new TemporaryFolder();
+ private File baseDir;
+
+ @Before
+ public void prepare() throws IOException {
+ baseDir = temp.newFolder();
+ sensor = new SymbolReferencesSensor();
+ fileSystem = new DefaultFileSystem();
+ when(context.fileSystem()).thenReturn(fileSystem);
+ }
+
+ @Test
+ public void testDescriptor() {
+ sensor.describe(new DefaultSensorDescriptor());
+ }
+
+ @Test
+ public void testNoExecutionIfNoSymbolFile() {
+ DefaultInputFile inputFile = new DefaultInputFile("src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ fileSystem.add(inputFile);
+ sensor.execute(context);
+ }
+
+ @Test
+ public void testExecution() throws IOException {
+ File symbol = new File(baseDir, "src/foo.xoo.symbol");
+ FileUtils.write(symbol, "1,4,7\n12,15,23\n\n#comment");
+ DefaultInputFile inputFile = new DefaultInputFile("src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo");
+ fileSystem.add(inputFile);
+ SymbolTableBuilder symbolTableBuilder = mock(SymbolTableBuilder.class);
+ when(context.symbolTableBuilder(inputFile)).thenReturn(symbolTableBuilder);
+
+ Symbol symbol1 = mock(Symbol.class);
+ when(symbolTableBuilder.newSymbol(1, 4)).thenReturn(symbol1);
+ Symbol symbol2 = mock(Symbol.class);
+ when(symbolTableBuilder.newSymbol(12, 15)).thenReturn(symbol2);
+
+ sensor.execute(context);
+
+ verify(symbolTableBuilder).newSymbol(1, 4);
+ verify(symbolTableBuilder).newReference(symbol1, 7);
+ verify(symbolTableBuilder).newSymbol(12, 15);
+ verify(symbolTableBuilder).newReference(symbol2, 23);
+ }
+
+}