@Before public void setUp() { FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); FileLinesContext fileLinesContext = mock(FileLinesContext.class); when(fileLinesContextFactory.createFor(Mockito.any(Resource.class))) .thenReturn(fileLinesContext); sensor = new JavaScriptSquidSensor(mock(RulesProfile.class), fileLinesContextFactory); }
@Before public void setUp() { FileLinesContextFactory fileLinesContextFactory = mock(FileLinesContextFactory.class); FileLinesContext fileLinesContext = mock(FileLinesContext.class); when(fileLinesContextFactory.createFor(any(InputFile.class))).thenReturn(fileLinesContext); CheckFactory checkFactory = new CheckFactory(mock(ActiveRules.class)); sensor = new PHPSensor( mock(ResourcePerspectives.class), fileSystem, fileLinesContextFactory, checkFactory, new NoSonarFilter()); }
private void saveLineMetrics(TreeVisitorContext context) { LineVisitor lineVisitor = new LineVisitor(context.getTopTree()); int linesNumber = lineVisitor.getLinesNumber(); Set<Integer> linesOfCode = lineVisitor.getLinesOfCode(); projectLinesOfCode.put(inputFile, linesOfCode); saveMetricOnFile(CoreMetrics.NCLOC, lineVisitor.getLinesOfCodeNumber()); CommentLineVisitor commentVisitor = new CommentLineVisitor(context.getTopTree(), ignoreHeaderComments); Set<Integer> commentLines = commentVisitor.getCommentLines(); saveMetricOnFile(CoreMetrics.COMMENT_LINES, commentVisitor.getCommentLineNumber()); noSonarFilter.noSonarInFile(this.inputFile, commentVisitor.noSonarLines()); FileLinesContext fileLinesContext = fileLinesContextFactory.createFor(this.inputFile); for (int line = 1; line <= linesNumber; line++) { int isCodeLine = linesOfCode.contains(line) ? 1 : 0; if (saveExecutableLines) { fileLinesContext.setIntValue(CoreMetrics.EXECUTABLE_LINES_DATA_KEY, line, isCodeLine); } fileLinesContext.setIntValue(CoreMetrics.NCLOC_DATA_KEY, line, isCodeLine); fileLinesContext.setIntValue( CoreMetrics.COMMENT_LINES_DATA_KEY, line, commentLines.contains(line) ? 1 : 0); } fileLinesContext.save(); }
public FileLinesContext fileLinesContextFor(File file) { return fileLinesContextFactory.createFor(inputFromIOFile(file)); }