当前位置: 首页>>代码示例>>Java>>正文


Java SensorContextTester类代码示例

本文整理汇总了Java中org.sonar.api.batch.sensor.internal.SensorContextTester的典型用法代码示例。如果您正苦于以下问题:Java SensorContextTester类的具体用法?Java SensorContextTester怎么用?Java SensorContextTester使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SensorContextTester类属于org.sonar.api.batch.sensor.internal包,在下文中一共展示了SensorContextTester类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testExecute

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void testExecute() throws IOException {

	Context t = new RulesDefinition.Context();
	ScriptAnalyzerRulesDefinition def = new ScriptAnalyzerRulesDefinition();
	def.define(t);

	File baseFile = folder.newFile("test.ps1");

	FileUtils.copyURLToFile(getClass().getResource("/testFiles/test.ps1"), baseFile);

	DefaultFileSystem fs = new DefaultFileSystem(folder.getRoot());
	DefaultInputFile ti = new DefaultInputFile("test", "test.ps1");
	ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));

	fs.add(ti);

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	ScriptAnalyzerSensor s = new ScriptAnalyzerSensor(fs, temp);
	s.execute(ctxTester);
	Assert.assertEquals(4, ctxTester.allIssues().size());

}
 
开发者ID:gretard,项目名称:sonar-ps-plugin,代码行数:24,代码来源:ScriptAnalyzerSensorTest.java

示例2: testExecute

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void testExecute() throws IOException, InterruptedException {

	File baseFile = folder.newFile("test.ps1");

	FileUtils.copyURLToFile(getClass().getResource("/testFiles/test.ps1"), baseFile);

	DefaultFileSystem fs = new DefaultFileSystem(folder.getRoot());
	DefaultInputFile ti = new DefaultInputFile("test", "test.ps1");
	ti.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
	ti.setLanguage(PowershellLanguage.KEY);
	fs.add(ti);

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	ctxTester.setFileSystem(fs);
	TokenizerSensor s = new TokenizerSensor(new Settings(), temp);
	s.execute(ctxTester);
	Assert.assertEquals(16, ctxTester.cpdTokens("test:test.ps1").size());
	Assert.assertEquals(1, ctxTester.highlightingTypeAt("test:test.ps1", 1, 5).size());

}
 
开发者ID:gretard,项目名称:sonar-ps-plugin,代码行数:22,代码来源:TokenizerSensorTest.java

示例3: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
  fileSystem.setEncoding(Charsets.UTF_8);
  file = tempFolder.newFile();
  inputFile = new DefaultInputFile("moduleKey", file.getName())
    .setLanguage("less")
    .setType(InputFile.Type.MAIN);
  fileSystem.add(inputFile);

  sensorContext = SensorContextTester.create(tempFolder.getRoot());
  sensorContext.setFileSystem(fileSystem);

  visitorContext = mock(TreeVisitorContext.class);
  highlighterVisitor = new LessSyntaxHighlighterVisitor(sensorContext);
  when(visitorContext.getFile()).thenReturn(file);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:LessSyntaxHighlighterVisitorTest.java

示例4: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
  fileSystem.setEncoding(Charsets.UTF_8);
  file = tempFolder.newFile();
  inputFile = new DefaultInputFile("moduleKey", file.getName())
    .setLanguage("scss")
    .setType(InputFile.Type.MAIN);
  fileSystem.add(inputFile);

  sensorContext = SensorContextTester.create(tempFolder.getRoot());
  sensorContext.setFileSystem(fileSystem);

  visitorContext = mock(TreeVisitorContext.class);
  highlighterVisitor = new ScssSyntaxHighlighterVisitor(sensorContext);
  when(visitorContext.getFile()).thenReturn(file);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:ScssSyntaxHighlighterVisitorTest.java

示例5: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
  fileSystem.setEncoding(Charsets.UTF_8);
  file = tempFolder.newFile();
  inputFile = new DefaultInputFile("moduleKey", file.getName())
    .setLanguage("css")
    .setType(InputFile.Type.MAIN);
  fileSystem.add(inputFile);

  sensorContext = SensorContextTester.create(tempFolder.getRoot());
  sensorContext.setFileSystem(fileSystem);

  visitorContext = mock(TreeVisitorContext.class);
  highlighterVisitor = new CssSyntaxHighlighterVisitor(sensorContext);
  when(visitorContext.getFile()).thenReturn(file);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:CssSyntaxHighlighterVisitorTest.java

示例6: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
private void setUp(String fileName) {
  File moduleBaseDir = new File("src/test/resources/metrics/");
  context = SensorContextTester.create(moduleBaseDir);

  DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName)
    .setModuleBaseDir(moduleBaseDir.toPath())
    .setLanguage("css")
    .setType(InputFile.Type.MAIN);

  context.fileSystem().add(inputFile);
  context.fileSystem().setEncoding(Charsets.UTF_8);

  CssMetricsVisitor metricsVisitor = new CssMetricsVisitor(context, mock(NoSonarFilter.class));

  TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class);
  when(treeVisitorContext.getFile()).thenReturn(inputFile.file());
  when(treeVisitorContext.getTopTree()).thenReturn(CssParser.createParser(Charsets.UTF_8).parse(inputFile.file()));

  metricsVisitor.scanTree(treeVisitorContext);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:21,代码来源:CssMetricsVisitorTest.java

示例7: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
private void setUp(String fileName) {
  File moduleBaseDir = new File("src/test/resources/metrics/");
  context = SensorContextTester.create(moduleBaseDir);

  DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName)
    .setModuleBaseDir(moduleBaseDir.toPath())
    .setLanguage("less")
    .setType(InputFile.Type.MAIN);

  context.fileSystem().add(inputFile);
  context.fileSystem().setEncoding(Charsets.UTF_8);

  LessMetricsVisitor metricsVisitor = new LessMetricsVisitor(context, mock(NoSonarFilter.class));

  TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class);
  when(treeVisitorContext.getFile()).thenReturn(inputFile.file());
  when(treeVisitorContext.getTopTree()).thenReturn(LessParser.createParser(Charsets.UTF_8).parse(inputFile.file()));

  metricsVisitor.scanTree(treeVisitorContext);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:21,代码来源:LessMetricsVisitorTest.java

示例8: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
private void setUp(String fileName) {
  File moduleBaseDir = new File("src/test/resources/metrics/");
  context = SensorContextTester.create(moduleBaseDir);

  DefaultInputFile inputFile = new DefaultInputFile("moduleKey", fileName)
    .setModuleBaseDir(moduleBaseDir.toPath())
    .setLanguage("scss")
    .setType(InputFile.Type.MAIN);

  context.fileSystem().add(inputFile);
  context.fileSystem().setEncoding(Charsets.UTF_8);

  ScssMetricsVisitor metricsVisitor = new ScssMetricsVisitor(context, mock(NoSonarFilter.class));

  TreeVisitorContext treeVisitorContext = mock(TreeVisitorContext.class);
  when(treeVisitorContext.getFile()).thenReturn(inputFile.file());
  when(treeVisitorContext.getTopTree()).thenReturn(ScssParser.createParser(Charsets.UTF_8).parse(inputFile.file()));

  metricsVisitor.scanTree(treeVisitorContext);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:21,代码来源:ScssMetricsVisitorTest.java

示例9: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
  fileSystem.setEncoding(Charsets.UTF_8);
  file = tempFolder.newFile();
  inputFile = new DefaultInputFile("moduleKey", file.getName())
    .setLanguage("css")
    .setType(InputFile.Type.MAIN);
  fileSystem.add(inputFile);

  sensorContext = SensorContextTester.create(tempFolder.getRoot());
  sensorContext.setFileSystem(fileSystem);

  visitorContext = mock(TreeVisitorContext.class);
  cpdVisitor = new CpdVisitor(sensorContext);
  when(visitorContext.getFile()).thenReturn(file);
}
 
开发者ID:racodond,项目名称:sonar-css-plugin,代码行数:18,代码来源:CpdVisitorTest.java

示例10: testExecute

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void testExecute() {
	// Sensor context
	final SensorContextTester sensorContext = SensorContextTester.create(new File("."));
	addFile(sensorContext, "/packagea/package-info.java", "java", Type.MAIN);
	addFile(sensorContext, "/packagea/ClassA.java", "java", Type.MAIN);
	addFile(sensorContext, "/packageb/package-info.java", "java", Type.TEST);
	addFile(sensorContext, "/packageb/ClassB.java", "java", Type.TEST);
	addFile(sensorContext, "/packagec/ClassC.pas", "pascal", Type.MAIN);

	// Execute
	final PackagesSensor subject = new PackagesSensor();
	subject.execute(sensorContext);

	// Check counts
	checkMetrics(sensorContext, "moduleKey:/packagea/package-info.java", 1, 1);
	checkMetrics(sensorContext, "moduleKey:/packagea/ClassA.java", null, 1);
	checkMetrics(sensorContext, "moduleKey:/packageb/package-info.java", null, null);
	checkMetrics(sensorContext, "moduleKey:/packageb/ClassB.java", null, null);
	checkMetrics(sensorContext, "moduleKey:/packagec/ClassC.pas", null, null);
}
 
开发者ID:willemsrb,项目名称:sonar-jdepend-plugin,代码行数:22,代码来源:PackagesSensorTest.java

示例11: test_symbolrefs_get_imported

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void test_symbolrefs_get_imported() throws FileNotFoundException {
  SensorContextTester tester = SensorContextTester.create(TEST_DATA_DIR);

  DefaultInputFile inputFile = new DefaultInputFile("dummyKey", TEST_FILE_PATH)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_FILE)));
  tester.fileSystem().add(inputFile);

  File protobuf = new File(TEST_DATA_DIR, SYMBOLREFS_OUTPUT_PROTOBUF_NAME);
  assertThat(protobuf.isFile()).withFailMessage("no such file: " + protobuf).isTrue();

  new SymbolRefsImporter(tester, f -> true).accept(protobuf.toPath());

  // a symbol is defined at this location, and referenced at 3 other locations
  assertThat(tester.referencesForSymbolAt(inputFile.key(), 25, 34)).hasSize(3);

  // ... other similar examples ...
  assertThat(tester.referencesForSymbolAt(inputFile.key(), 25, 43)).hasSize(3);
  assertThat(tester.referencesForSymbolAt(inputFile.key(), 56, 30)).hasSize(1);
  assertThat(tester.referencesForSymbolAt(inputFile.key(), 56, 37)).hasSize(1);
}
 
开发者ID:SonarSource,项目名称:sonar-dotnet-shared-library,代码行数:22,代码来源:SymbolRefsImporterTest.java

示例12: test_issues_get_imported

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void test_issues_get_imported() throws FileNotFoundException {
  SensorContextTester tester = SensorContextTester.create(TEST_DATA_DIR);

  DefaultInputFile inputFile = new DefaultInputFile("dummyKey", TEST_FILE_PATH)
    .initMetadata(new FileMetadata().readMetadata(new FileReader(TEST_FILE)));
  tester.fileSystem().add(inputFile);

  File protobuf = new File(TEST_DATA_DIR, ISSUES_OUTPUT_PROTOBUF_NAME);
  assertThat(protobuf.isFile()).withFailMessage("no such file: " + protobuf).isTrue();

  new IssuesImporter(tester, "dummy", f -> true).accept(protobuf.toPath());

  Collection<Issue> issues = tester.allIssues();
  assertThat(issues).hasSize(6);

  assertThat(issues.stream().map(p -> p.ruleKey().rule()).collect(Collectors.toList()))
    .containsOnly("S1186", "S1172", "S1118", "S101", "S101", "S105");

  TextRange exactLocation = issues.stream().filter(i -> i.ruleKey().rule().equals("S1186")).findFirst().get().primaryLocation().textRange();
  assertThat(exactLocation.start().line() != exactLocation.end().line() || exactLocation.start().lineOffset() != exactLocation.end().lineOffset()).isTrue();

  exactLocation = issues.stream().filter(i -> i.ruleKey().rule().equals("S105")).findFirst().get().primaryLocation().textRange();
  assertThat(exactLocation).isNull();
}
 
开发者ID:SonarSource,项目名称:sonar-dotnet-shared-library,代码行数:26,代码来源:IssuesImporterTest.java

示例13: testSettings

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void testSettings() {
	final MapSettings settings = new MapSettings();
	final SensorContextTester sensorContext = SensorContextTester.create(new File(""));
	sensorContext.setSettings(settings);
	assertNull(SensorUtil.geReportFile(sensorContext));

	settings.setProperty(XanitizerSonarQubePlugin.XAN_XML_REPORT_FILE, "");
	assertNull(SensorUtil.geReportFile(sensorContext));

	settings.setProperty(XanitizerSonarQubePlugin.XAN_XML_REPORT_FILE, "/doesNotExist.xml");
	assertNull(SensorUtil.geReportFile(sensorContext));

	final String reportFileString = getClass()
			.getResource("/webgoat/webgoat-Findings-List-all.xml").getFile();
	settings.setProperty(XanitizerSonarQubePlugin.XAN_XML_REPORT_FILE, reportFileString);
	final File reportFile = SensorUtil.geReportFile(sensorContext);
	assertNotNull(reportFile);
	assertTrue(reportFile.isFile());
	assertEquals(new File(reportFileString), reportFile);
}
 
开发者ID:RIGS-IT,项目名称:sonar-xanitizer,代码行数:22,代码来源:PluginTest.java

示例14: setUp

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Before
public void setUp() throws IOException {
  DefaultFileSystem fileSystem = new DefaultFileSystem(tempFolder.getRoot());
  fileSystem.setEncoding(Charsets.UTF_8);
  file = tempFolder.newFile();
  inputFile = new DefaultInputFile("moduleKey", file.getName())
    .setLanguage("gherkin")
    .setType(InputFile.Type.MAIN);
  fileSystem.add(inputFile);

  sensorContext = SensorContextTester.create(tempFolder.getRoot());
  sensorContext.setFileSystem(fileSystem);
  visitorContext = mock(TreeVisitorContext.class);
  highlighterVisitor = new SyntaxHighlighterVisitor(sensorContext);
  when(visitorContext.getFile()).thenReturn(file);
}
 
开发者ID:racodond,项目名称:sonar-gherkin-plugin,代码行数:17,代码来源:SyntaxHighlighterVisitorTest.java

示例15: testHighlighting2

import org.sonar.api.batch.sensor.internal.SensorContextTester; //导入依赖的package包/类
@Test
public void testHighlighting2() throws Throwable {

	Settings settings = new Settings();

	File baseFile = folder.newFile("test.sql");
	FileUtils.write(baseFile, "SELECT * FROM dbo.test");

	DefaultInputFile file1 = new DefaultInputFile("test", "test.sql");

	file1.initMetadata(new String(Files.readAllBytes(baseFile.toPath())));
	file1.setLanguage(TSQLLanguage.KEY);

	SensorContextTester ctxTester = SensorContextTester.create(folder.getRoot());
	ctxTester.fileSystem().add(file1);
	HighlightingSensor sensor = new HighlightingSensor(settings);
	sensor.execute(ctxTester);

	Assert.assertEquals(1, ctxTester.highlightingTypeAt("test:test.sql", 1, 5).size());
	Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 2, 0).size());
	Assert.assertEquals(0, ctxTester.highlightingTypeAt("test:test.sql", 5, 0).size());
	Assert.assertEquals(1, ctxTester.cpdTokens("test:test.sql").size());

}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:25,代码来源:HighlightingSensorTest.java


注:本文中的org.sonar.api.batch.sensor.internal.SensorContextTester类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。