diff options
author | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-02-09 00:07:24 +0400 |
---|---|---|
committer | Evgeny Mandrikov <mandrikov@gmail.com> | 2012-02-09 01:56:03 +0400 |
commit | 4eedeb8c01eb478ef0015de0a46849d781766114 (patch) | |
tree | 48c6ea53fcc20fa6efd58594355666118fe0fe73 /plugins/sonar-squid-java-plugin/src/test/java/org | |
parent | fff856ad40b5a27148e6f1f48819797ae2f0c94f (diff) | |
download | sonarqube-4eedeb8c01eb478ef0015de0a46849d781766114.tar.gz sonarqube-4eedeb8c01eb478ef0015de0a46849d781766114.zip |
SONAR-3210 Compute new measure for Java files - LoC in file
Diffstat (limited to 'plugins/sonar-squid-java-plugin/src/test/java/org')
-rw-r--r-- | plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileLinesVisitorTest.java | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileLinesVisitorTest.java b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileLinesVisitorTest.java new file mode 100644 index 00000000000..75edd60fb84 --- /dev/null +++ b/plugins/sonar-squid-java-plugin/src/test/java/org/sonar/java/ast/visitor/FileLinesVisitorTest.java @@ -0,0 +1,66 @@ +/* + * 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.java.ast.visitor; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.sonar.api.batch.SensorContext; +import org.sonar.api.measures.CoreMetrics; +import org.sonar.api.measures.Measure; +import org.sonar.api.measures.PersistenceMode; +import org.sonar.api.resources.Resource; +import org.sonar.java.ast.JavaAstScanner; +import org.sonar.java.ast.SquidTestUtils; +import org.sonar.java.squid.JavaSquidConfiguration; +import org.sonar.plugins.squid.SonarAccessor; +import org.sonar.squid.Squid; + +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.*; + +public class FileLinesVisitorTest { + + private Squid squid; + private SensorContext context; + + @Before + public void setUp() { + squid = new Squid(new JavaSquidConfiguration()); + context = mock(SensorContext.class); + } + + @Test + public void analyseTestNcloc() { + squid.register(SonarAccessor.class).setSensorContext(context); + squid.register(JavaAstScanner.class).scanFile(SquidTestUtils.getInputFile("/metrics/ncloc/TestNcloc.java")); + + ArgumentCaptor<Resource> resourceCaptor = ArgumentCaptor.forClass(Resource.class); + ArgumentCaptor<Measure> measureCaptor = ArgumentCaptor.forClass(Measure.class); + verify(context, times(1)).saveMeasure(resourceCaptor.capture(), measureCaptor.capture()); + assertThat(resourceCaptor.getValue().getKey(), is("[default].TestNcloc")); + Measure measure = measureCaptor.getValue(); + assertThat(measure.getMetricKey(), is(CoreMetrics.NCLOC_DATA_KEY)); + assertThat(measure.getPersistenceMode(), is(PersistenceMode.DATABASE)); + assertThat(measure.getData(), is("1,3,4,5,6,7,8,13,14,15,16,17,19,20,21,22,23,24,25,26,27,28,29,30,32,39")); + } + +} |