@Test
  public void should_register_tests() throws URISyntaxException {
    SensorContextTester context = SensorContextTester.create(new File(""));

    MutableTestCase testCase = mock(MutableTestCase.class);
    when(testCase.setDurationInMs(anyLong())).thenReturn(testCase);
    when(testCase.setStatus(any(TestCase.Status.class))).thenReturn(testCase);
    when(testCase.setMessage(anyString())).thenReturn(testCase);
    when(testCase.setStackTrace(anyString())).thenReturn(testCase);
    when(testCase.setType(anyString())).thenReturn(testCase);
    MutableTestPlan testPlan = mock(MutableTestPlan.class);
    when(testPlan.addTestCase(anyString())).thenReturn(testCase);
    when(perspectives.as(
            eq(MutableTestPlan.class),
            argThat(
                new ArgumentMatcher<InputFile>() {
                  @Override
                  public boolean matches(Object o) {
                    if (o instanceof InputFile) {
                      return ":ch.hortis.sonar.mvn.mc.MetricsCollectorRegistryTest"
                          .equals(((InputFile) o).key());
                    }
                    return false;
                  }
                })))
        .thenReturn(testPlan);

    parser.collect(context, getDir("multipleReports"), true);

    verify(testPlan).addTestCase("testGetUnKnownCollector");
    verify(testPlan).addTestCase("testGetJDependsCollector");
  }
Exemplo n.º 2
0
 public void decorate(Resource resource, DecoratorContext context) {
   Issuable issuable = perspectives.as(Issuable.class, resource);
   if (issuable != null && shouldSaveMeasure(context)) {
     List<Issue> issues = newArrayList(issuable.issues());
     saveMeasures(context, issues);
   }
 }
 @Override
 public void decorate(Resource resource, DecoratorContext context) {
   Issuable issuable = perspectives.as(Issuable.class, resource);
   if (issuable != null) {
     int falsePositives = 0;
     for (Issue issue : issuable.resolvedIssues()) {
       if (Issue.RESOLUTION_FALSE_POSITIVE.equals(issue.resolution())) {
         falsePositives++;
       }
     }
     saveMeasure(context, CoreMetrics.FALSE_POSITIVE_ISSUES, falsePositives);
   }
 }
 @Override
 protected void processFile(
     InputFile inputFile,
     org.sonar.api.resources.File sonarFile,
     SensorContext context,
     RuleKey ruleKey,
     String languageKey) {
   Issuable issuable = perspectives.as(Issuable.class, sonarFile);
   issuable.addIssue(
       issuable
           .newIssueBuilder()
           .ruleKey(ruleKey)
           .effortToFix(settings.getDouble(EFFORT_TO_FIX_PROPERTY))
           .message("This issue is generated on each file")
           .build());
 }
Exemplo n.º 5
0
 private void saveIssues(Set<Edge> feedbackEdges) {
   for (Edge feedbackEdge : feedbackEdges) {
     for (Dependency subDependency :
         resourceMapping.getSubDependencies((Dependency) feedbackEdge)) {
       Resource fromFile = subDependency.getFrom();
       Resource toFile = subDependency.getTo();
       Issuable issuable = resourcePerspectives.as(Issuable.class, fromFile);
       if (issuable != null) {
         issuable.addIssue(
             issuable
                 .newIssueBuilder()
                 .ruleKey(CycleBetweenPackagesCheck.RULE_KEY)
                 .message(
                     "Remove the dependency on the source file \""
                         + toFile.getLongName()
                         + "\" to break a package cycle.")
                 .build());
       }
     }
   }
 }
  @Override
  public void decorate(Resource resource, DecoratorContext context) {
    if (!enabled) {
      return;
    }

    logger.trace("Decorating resource [{}]", resource.getKey());

    Issuable issuable = perspectives.as(Issuable.class, resource);
    if (issuable == null) {
      logger.trace("Resource [{}] is not issuable", resource.getKey());
      return;
    }

    List<Issue> unresolvedIssues = issuable.issues();
    if (unresolvedIssues == null) {
      logger.debug("No unresolved issues found for resource [{}]", resource.getKey());
      return;
    }

    treatUnresolvedIssues(context, unresolvedIssues);
  }
Exemplo n.º 7
0
 public Highlightable highlightableFor(File file) {
   return resourcePerspectives.as(Highlightable.class, inputFromIOFile(file));
 }
Exemplo n.º 8
0
 public Symbolizable symbolizableFor(File file) {
   return resourcePerspectives.as(Symbolizable.class, inputFromIOFile(file));
 }