@Test public void shouldReuseReport() throws Exception { Project project = createProject(); FindbugsExecutor executor = mock(FindbugsExecutor.class); SensorContext context = mock(SensorContext.class); Configuration conf = mock(Configuration.class); File xmlFile = new File(getClass().getResource("/org/sonar/plugins/findbugs/findbugsReport.xml").toURI()); when(conf.getString(CoreProperties.FINDBUGS_REPORT_PATH)).thenReturn(xmlFile.getAbsolutePath()); when(project.getConfiguration()).thenReturn(conf); when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor); analyser.analyse(project, context); verify(executor, never()).execute(); verify(context, times(2)).saveViolation(any(Violation.class)); Violation wanted = Violation.create((Rule) null, new JavaFile("org.sonar.commons.ZipUtils")) .setMessage( "Empty zip file entry created in org.sonar.commons.ZipUtils._zip(String, File, ZipOutputStream)") .setLineId(107); verify(context).saveViolation(argThat(new IsViolation(wanted))); wanted = Violation.create((Rule) null, new JavaFile("org.sonar.commons.resources.MeasuresDao")) .setMessage( "The class org.sonar.commons.resources.MeasuresDao$1 could be refactored into a named _static_ inner class") .setLineId(56); verify(context).saveViolation(argThat(new IsViolation(wanted))); }
protected boolean isEnabled(Project project) { return project .getConfiguration() .getBoolean( CoreProperties.CORE_IMPORT_SOURCES_PROPERTY, CoreProperties.CORE_IMPORT_SOURCES_DEFAULT_VALUE); }
public Css(Project project) { this(); List<?> extensions = project.getConfiguration().getList(ProjectConfiguration.FILE_EXTENSIONS); if (extensions != null && extensions.size() > 0 && !StringUtils.isEmpty((String) extensions.get(0))) { fileSuffixes = new String[extensions.size()]; for (int i = 0; i < extensions.size(); i++) { fileSuffixes[i] = extensions.get(i).toString().trim(); } } }
@Test public void shouldIgnoreNotActiveViolations() throws Exception { Project project = createProject(); FindbugsExecutor executor = mock(FindbugsExecutor.class); SensorContext context = mock(SensorContext.class); Configuration conf = mock(Configuration.class); File xmlFile = new File( getClass() .getResource("/org/sonar/plugins/findbugs/findbugsReportWithUnknownRule.xml") .toURI()); when(conf.getString(CoreProperties.FINDBUGS_REPORT_PATH)).thenReturn(xmlFile.getAbsolutePath()); when(project.getConfiguration()).thenReturn(conf); when(context.getResource(any(Resource.class))).thenReturn(new JavaFile("org.sonar.MyClass")); FindbugsSensor analyser = new FindbugsSensor(createRulesProfileWithActiveRules(), new FakeRuleFinder(), executor); analyser.analyse(project, context); verify(context, never()).saveViolation(any(Violation.class)); }