### Question:
OpenApiScannerSensor implements Sensor { @Override public void execute(SensorContext context) { FilePredicates p = context.fileSystem().predicates(); OpenApiProperties openApiProperties = new OpenApiProperties(); scanFiles(context, p, openApiProperties.getV2FilesPattern(context), true); scanFiles(context, p, openApiProperties.getV3FilesPattern(context), false); } OpenApiScannerSensor(CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory, NoSonarFilter noSonarFilter);  OpenApiScannerSensor(CheckFactory checkFactory, FileLinesContextFactory fileLinesContextFactory, NoSonarFilter noSonarFilter, @Nullable OpenApiCustomRuleRepository[] customRuleRepositories); @Override void describe(SensorDescriptor descriptor); @Override void execute(SensorContext context); void scanFiles(SensorContext context, FilePredicates p, String[] pathPatterns, boolean isV2);  }### Answer:
@Test public void test_issues() { activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.REPOSITORY_KEY, "PathMaskerading")) .activate() .build(); InputFile inputFile = inputFile("file1.yaml"); sensor().execute(context); String key = "moduleKey:file1.yaml"; assertThat(context.measure(key, CoreMetrics.NCLOC).value()).isEqualTo(29); assertThat(context.measure(key, OpenApiMetrics.PATHS_COUNT).value()).isEqualTo(2); assertThat(context.measure(key, OpenApiMetrics.OPERATIONS_COUNT).value()).isEqualTo(2); assertThat(context.measure(key, OpenApiMetrics.SCHEMAS_COUNT).value()).isEqualTo(2); assertThat(context.measure(key, CoreMetrics.COMPLEXITY).value()).isEqualTo(8); assertThat(context.measure(key, CoreMetrics.COMMENT_LINES).value()).isEqualTo(1); assertThat(context.allIssues()).hasSize(1); Issue issue = Iterables.get(context.allIssues(), 0); IssueLocation issueLocation = issue.primaryLocation(); assertThat(issueLocation.inputComponent()).isEqualTo(inputFile); if (issue.ruleKey().rule().equals("PathMaskerading")) { assertThat(issueLocation.message()).isEqualTo(PathMaskeradingCheck.MASK_MESSAGE); assertThat(issueLocation.textRange()).isEqualTo(inputFile.newRange(6, 2, 6, 15)); assertThat(issue.flows()).hasSize(1); assertThat(issue.gap()).isNull(); } assertThat(context.allAnalysisErrors()).isEmpty(); }
@Test public void parse_error() { inputFile("parse-error.yaml"); activeRules = (new ActiveRulesBuilder()) .create(RuleKey.of(CheckList.REPOSITORY_KEY, ParsingErrorCheck.CHECK_KEY)) .activate() .build(); sensor().execute(context); assertThat(context.allIssues()).hasSize(2); assertThat(context.allAnalysisErrors()) .extracting(e -> e.inputFile().filename(), e -> e.location().line(), e -> e.location().lineOffset(), AnalysisError::message) .containsExactlyInAnyOrder( tuple("parse-error.yaml", 3, 2, "Missing required properties: [version]"), tuple("parse-error.yaml", 7, 6, "Missing required properties: [responses]") ); }
@Test public void cancelled_analysis() { InputFile inputFile = inputFile("file1.yaml"); activeRules = (new ActiveRulesBuilder()).build(); context.setCancelled(true); sensor().execute(context); assertThat(context.allAnalysisErrors()).isEmpty(); }