use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.
the class FakeRule method shouldParseOnlyWantedProfile.
@Test
public void shouldParseOnlyWantedProfile() {
RuleFinder ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
public Rule answer(InvocationOnMock iom) throws Throwable {
return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
}
});
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages);
assertThat(profile.getActiveRule("squid", "fake")).isNotNull();
assertThat(profile.getActiveRule("squid", "other")).isNull();
}
use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.
the class FakeRule method shouldParseAnnotatedClasses.
@Test
public void shouldParseAnnotatedClasses() {
RuleFinder ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
public Rule answer(InvocationOnMock iom) throws Throwable {
return Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
}
});
ValidationMessages messages = ValidationMessages.create();
RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages);
assertThat(profile.getName()).isEqualTo("Foo way");
assertThat(profile.getLanguage()).isEqualTo("java");
assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER);
assertThat(messages.hasErrors()).isFalse();
}
use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.
the class DefaultIndexTest method createIndex.
@Before
public void createIndex() throws IOException {
ruleFinder = mock(RuleFinder.class);
componentStore = mock(InputComponentStore.class);
componentTree = mock(InputComponentTree.class);
index = new DefaultIndex(componentStore, componentTree, mock(MeasureCache.class), mock(MetricFinder.class));
baseDir = temp.newFolder();
ProjectDefinition rootDef = ProjectDefinition.create().setKey("project").setBaseDir(baseDir);
ProjectDefinition moduleADef = ProjectDefinition.create().setKey("moduleA").setBaseDir(new java.io.File(baseDir, "moduleA"));
ProjectDefinition moduleBDef = ProjectDefinition.create().setKey("moduleB").setBaseDir(new java.io.File(baseDir, "moduleB"));
ProjectDefinition moduleB1Def = ProjectDefinition.create().setKey("moduleB1").setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1"));
rootDef.addSubProject(moduleADef);
rootDef.addSubProject(moduleBDef);
moduleBDef.addSubProject(moduleB1Def);
project = new Project(rootDef);
moduleA = new Project(moduleADef);
moduleB = new Project(moduleBDef);
moduleB1 = new Project(moduleB1Def);
RulesProfile rulesProfile = RulesProfile.create();
rule = Rule.create("repoKey", "ruleKey", "Rule");
rule.setId(1);
rulesProfile.activateRule(rule, null);
index.setCurrentStorage(mock(DefaultSensorStorage.class));
}
use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.
the class WebServerRuleFinderImplTest method stopCaching_restores_non_caching_delegate.
@Test
public void stopCaching_restores_non_caching_delegate() {
RuleFinder nonCachingDelegate = underTest.delegate;
underTest.startCaching();
underTest.stopCaching();
assertThat(underTest.delegate).isSameAs(nonCachingDelegate);
}
use of org.sonar.api.rules.RuleFinder in project sonarqube by SonarSource.
the class XMLProfileParserTest method newRuleFinder.
private RuleFinder newRuleFinder() {
RuleFinder ruleFinder = mock(RuleFinder.class);
when(ruleFinder.findByKey(anyString(), anyString())).thenAnswer(new Answer<Rule>() {
public Rule answer(InvocationOnMock iom) {
Rule rule = Rule.create((String) iom.getArguments()[0], (String) iom.getArguments()[1], (String) iom.getArguments()[1]);
rule.createParameter("format");
rule.createParameter("message");
return rule;
}
});
return ruleFinder;
}
Aggregations