Package org.sonar.api.batch

Examples of org.sonar.api.batch.SensorContext


  }

  @Test
  public void shouldCreateVersionEvent() {
    VersionEventsSensor sensor = new VersionEventsSensor();
    SensorContext context = mock(SensorContext.class);

    Project project = mock(Project.class);
    when(project.getAnalysisVersion()).thenReturn("1.5-SNAPSHOT");

    sensor.analyse(project, context);
View Full Code Here


    Event sameVersionEvent = mockVersionEvent("1.5-SNAPSHOT");
    Event otherEvent = mockVersionEvent("1.4");
    Event anotherEvent = mockVersionEvent("1.3-SNAPSHOT");

    VersionEventsSensor sensor = new VersionEventsSensor();
    SensorContext context = mock(SensorContext.class);

    Project project = mock(Project.class);
    when(project.getAnalysisVersion()).thenReturn("1.5-SNAPSHOT");

    when(context.getEvents(project)).thenReturn(Lists.newArrayList(sameVersionEvent, otherEvent, anotherEvent));

    sensor.analyse(project, context);

    verify(context).deleteEvent(sameVersionEvent);
    verify(context).createEvent(eq(project), eq("1.5-SNAPSHOT"), (String) isNull(), eq(Event.CATEGORY_VERSION), (Date) isNull());
View Full Code Here

    Settings settings = new Settings();
    settings.setProperty(CoreProperties.LINKS_HOME_PAGE, "http://home");
    DefaultI18n defaultI18n = mock(DefaultI18n.class);
    when(defaultI18n.message(Locale.getDefault(), "project_links.homepage", CoreProperties.LINKS_HOME_PAGE)).thenReturn("HOME");
    Project project = mock(Project.class);
    SensorContext context = mock(SensorContext.class);

    new ProjectLinksSensor(settings, defaultI18n).analyse(project, context);

    verify(context).saveLink(argThat(new MatchLink("homepage", "HOME", "http://home")));
  }
View Full Code Here

    Settings settings = new Settings();
    settings.setProperty(CoreProperties.LINKS_HOME_PAGE, "");
    DefaultI18n defaultI18n = mock(DefaultI18n.class);
    when(defaultI18n.message(Locale.getDefault(), "project_links.homepage", CoreProperties.LINKS_HOME_PAGE)).thenReturn("HOME");
    Project project = mock(Project.class);
    SensorContext context = mock(SensorContext.class);

    new ProjectLinksSensor(settings, defaultI18n).analyse(project, context);

    verify(context).deleteLink("homepage");
  }
View Full Code Here

public final class CoberturaMeasuresPersistorTest {

  @Test
  public void shouldNotPersistMeasuresForUnknownFiles() {
    final Project project = new Project("Test");
    final SensorContext context = mock(SensorContext.class);
    final Map<String, CoverageMeasuresBuilder> measures = new HashMap<String, CoverageMeasuresBuilder>();
    measures.put("DummyResource", CoverageMeasuresBuilder.create());

    project.setFileSystem(mock(ProjectFileSystem.class));
View Full Code Here

  @Test
  public void shouldPersistMeasuresForKnownFiles() {
    final Project project = new Project("Test");
    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("dummy/test");
    final SensorContext context = mock(SensorContext.class);
    final ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
    final List<File> sourceDirs = new ArrayList<File>();
    final Map<String, CoverageMeasuresBuilder> measures = new HashMap<String, CoverageMeasuresBuilder>();
    final CoverageMeasuresBuilder measureBuilder = CoverageMeasuresBuilder.create();

    sourceDirs.add(new File("/dummy"));
    measures.put("/dummy/test", measureBuilder);
    measureBuilder.setHits(99, 99);
    measureBuilder.setConditions(99, 99, 1);

    when(fileSystem.getSourceDirs()).thenReturn(sourceDirs);
    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    project.setFileSystem(fileSystem);

    final CoverageMeasuresPersistor testedPersistor = new CoverageMeasuresPersistor(project, context);
    testedPersistor.saveMeasures(measures);
View Full Code Here

  @Test
  public void parseReportShouldReturnACollectionOfViolationsWhenTheReportIsNotEmpty() {
    final Project project = new Project("Test");
    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("dummy/test");
    final SensorContext context = mock(SensorContext.class);
    final ProjectFileSystem fileSystem = mock(ProjectFileSystem.class);
    final List<File> sourceDirs = new ArrayList<File>();

    final OCLintParser testedParser = new OCLintParser(project, context);

    sourceDirs.add(new File("/dummy"));
    when(fileSystem.getSourceDirs()).thenReturn(sourceDirs);
    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);
    project.setFileSystem(fileSystem);

    final Collection<Violation> violations = testedParser.parseReport(new StringInputStream(VALID_REPORT));
    assertFalse(violations.isEmpty());
  }
View Full Code Here

  @Test
  public void streamAddAviolationForALineInTheReport() throws XMLStreamException {
    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("test");
    givenAProject().containingSourceDirectory("dummy");
    final SensorContext context = mock(SensorContext.class);

    final Collection<Violation> parseResults = new ArrayList<Violation>();
    final StaxParser parser = new StaxParser(new OCLintXMLStreamHandler(parseResults, project(), context));

    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    parser.parse(new StringInputStream(VALID_REPORT));

    assertFalse(parseResults.isEmpty());
  }
View Full Code Here

  @Test
  public void violationContainsFileResource() throws XMLStreamException {
    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("test");
    givenAProject().containingSourceDirectory("dummy");
    final SensorContext context = mock(SensorContext.class);

    final List<Violation> parseResults = new ArrayList<Violation>();
    final StaxParser parser = new StaxParser(new OCLintXMLStreamHandler(parseResults, project(), context));

    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    parser.parse(new StringInputStream(VALID_REPORT));

    assertEquals(dummyFile, parseResults.get(0).getResource());
  }
View Full Code Here

  @Test
  public void violationContainsTheMessageFromTheReport() throws XMLStreamException {
    final org.sonar.api.resources.File dummyFile = new org.sonar.api.resources.File("test");
    givenAProject().containingSourceDirectory("dummy");
    final SensorContext context = mock(SensorContext.class);

    final List<Violation> parseResults = new ArrayList<Violation>();
    final StaxParser parser = new StaxParser(new OCLintXMLStreamHandler(parseResults, project(), context));

    when(context.getResource(any(Resource.class))).thenReturn(dummyFile);

    parser.parse(new StringInputStream(VALID_REPORT));

    assertEquals(DESCRIPTION, parseResults.get(0).getMessage());
  }
View Full Code Here

TOP

Related Classes of org.sonar.api.batch.SensorContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.