diff options
author | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-04 15:50:09 +0200 |
---|---|---|
committer | Jean-Baptiste Vilain <jean-baptiste.vilain@sonarsource.com> | 2013-04-04 15:50:09 +0200 |
commit | a3521edd7c7cc726e5aa2161e8cc0f76ecd571dc (patch) | |
tree | cb5805817d86d89e1098e3d42059cf85f76a7601 /sonar-core/src/test | |
parent | 5a38f5a540005d0703a3ef870c95f46469027f1a (diff) | |
download | sonarqube-a3521edd7c7cc726e5aa2161e8cc0f76ecd571dc.tar.gz sonarqube-a3521edd7c7cc726e5aa2161e8cc0f76ecd571dc.zip |
(SONAR-3893) Improve the highlighter API to not depend on sonar-channel and allow to work on multi-line tokens
Diffstat (limited to 'sonar-core/src/test')
4 files changed, 107 insertions, 6 deletions
diff --git a/sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java b/sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java new file mode 100644 index 00000000000..9990218d2ee --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/source/DefaultHighlightableTest.java @@ -0,0 +1,57 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.core.source; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.sonar.api.component.Component; +import org.sonar.api.scan.source.HighlightableTextType; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class DefaultHighlightableTest { + + @Rule + public ExpectedException throwable = ExpectedException.none(); + + @Test + public void should_register_highlighting_rule() throws Exception { + + Component mockComponent = mock(Component.class); + + DefaultHighlightable highlightable = new DefaultHighlightable(mockComponent); + highlightable.highlightText(1, 10, HighlightableTextType.KEYWORD); + + assertThat(highlightable.getHighlightingRules().getSyntaxHighlightingRuleSet()).hasSize(1); + } + + @Test + public void should_reject_any_call_to_component() throws Exception { + + Component mockComponent = mock(Component.class); + + throwable.expect(UnsupportedOperationException.class); + + DefaultHighlightable highlightable = new DefaultHighlightable(mockComponent); + highlightable.component(); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java new file mode 100644 index 00000000000..427feb7ce9e --- /dev/null +++ b/sonar-core/src/test/java/org/sonar/core/source/HighlightableBuilderTest.java @@ -0,0 +1,41 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2008-2012 SonarSource + * mailto:contact AT sonarsource DOT com + * + * Sonar is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * Sonar is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Sonar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 + */ +package org.sonar.core.source; + +import org.junit.Test; +import org.sonar.api.component.Component; +import org.sonar.api.scan.source.Highlightable; + +import static org.fest.assertions.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +public class HighlightableBuilderTest { + + @Test + public void should_load_default_perspective() throws Exception { + + Component mockComponent = mock(Component.class); + + HighlightableBuilder builder = new HighlightableBuilder(); + Highlightable perspective = builder.loadPerspective(Highlightable.class, mockComponent); + + assertThat(perspective).isInstanceOf(DefaultHighlightable.class); + } +} diff --git a/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java index fa493c879f0..4c03a6f457e 100644 --- a/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/test/TestPlanBuilderTest.java @@ -30,15 +30,17 @@ import static org.fest.assertions.Assertions.assertThat; public class TestPlanBuilderTest { @Test public void test_path() { - TestPlanBuilder builder = new TestPlanBuilder(); + + ScanGraph graph = ScanGraph.create(); + TestPlanBuilder builder = new TestPlanBuilder(graph); assertThat(builder.path().getElements()).isNotEmpty(); } @Test public void should_not_load_missing_perspective() { - TestPlanBuilder builder = new TestPlanBuilder(); ScanGraph graph = ScanGraph.create(); + TestPlanBuilder builder = new TestPlanBuilder(graph); ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); assertThat(builder.load(file)).isNull(); @@ -46,8 +48,8 @@ public class TestPlanBuilderTest { @Test public void should_create_perspective() { - TestPlanBuilder builder = new TestPlanBuilder(); ScanGraph graph = ScanGraph.create(); + TestPlanBuilder builder = new TestPlanBuilder(graph); ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); MutableTestPlan plan = builder.create(file); diff --git a/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java b/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java index fa8eed08924..a21be60aad7 100644 --- a/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/test/TestableBuilderTest.java @@ -30,15 +30,16 @@ import static org.fest.assertions.Assertions.assertThat; public class TestableBuilderTest { @Test public void test_path() { - TestableBuilder builder = new TestableBuilder(); + ScanGraph graph = ScanGraph.create(); + TestableBuilder builder = new TestableBuilder(graph); assertThat(builder.path().getElements()).isNotEmpty(); } @Test public void should_not_load_missing_perspective() { - TestableBuilder builder = new TestableBuilder(); ScanGraph graph = ScanGraph.create(); + TestableBuilder builder = new TestableBuilder(graph); ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); assertThat(builder.load(file)).isNull(); @@ -46,8 +47,8 @@ public class TestableBuilderTest { @Test public void should_create_perspective() { - TestableBuilder builder = new TestableBuilder(); ScanGraph graph = ScanGraph.create(); + TestableBuilder builder = new TestableBuilder(graph); ComponentVertex file = graph.addComponent(MockSourceFile.createMain("org.foo.Bar")); MutableTestable testable = builder.create(file); |