diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2014-09-01 10:01:37 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2014-09-01 10:01:37 +0200 |
commit | 3631a75a1a88e18ebc6b909e3ee430b5b61831af (patch) | |
tree | b3fb3c6ac56cb6234f569acba9752d5c0c6c5e6f /plugins/sonar-xoo-plugin/src/test | |
parent | 629ca066726a98fcc9e068e9b854d23133eab715 (diff) | |
download | sonarqube-3631a75a1a88e18ebc6b909e3ee430b5b61831af.tar.gz sonarqube-3631a75a1a88e18ebc6b909e3ee430b5b61831af.zip |
Improve code coverage
Diffstat (limited to 'plugins/sonar-xoo-plugin/src/test')
-rw-r--r-- | plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java new file mode 100644 index 00000000000..a8a3e04837c --- /dev/null +++ b/plugins/sonar-xoo-plugin/src/test/java/org/sonar/xoo/lang/SyntaxHighlightingSensorTest.java @@ -0,0 +1,67 @@ +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.highlighting.HighlightingBuilder; +import org.sonar.api.batch.sensor.highlighting.TypeOfText; +import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; + +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 SyntaxHighlightingSensorTest { + + private SyntaxHighlightingSensor 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 SyntaxHighlightingSensor(); + fileSystem = new DefaultFileSystem(); + when(context.fileSystem()).thenReturn(fileSystem); + } + + @Test + public void testDescriptor() { + sensor.describe(new DefaultSensorDescriptor()); + } + + @Test + public void testNoExecutionIfNoSyntaxFile() { + 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.highlighting"); + FileUtils.write(symbol, "1:4:k\n12:15:cppd\n\n#comment"); + DefaultInputFile inputFile = new DefaultInputFile("src/foo.xoo").setAbsolutePath(new File(baseDir, "src/foo.xoo").getAbsolutePath()).setLanguage("xoo"); + fileSystem.add(inputFile); + HighlightingBuilder builder = mock(HighlightingBuilder.class); + when(context.highlightingBuilder(inputFile)).thenReturn(builder); + + sensor.execute(context); + + verify(builder).highlight(1, 4, TypeOfText.KEYWORD); + verify(builder).highlight(12, 15, TypeOfText.CPP_DOC); + verify(builder).done(); + } +} |