@Test
  public void should_not_execute_if_disabled() {
    when(conf.isEnabled()).thenReturn(false);

    boolean shouldExecute = scmActivitySensor.shouldExecuteOnProject(project);

    assertThat(shouldExecute).isFalse();
  }
  @Test
  public void should_execute() {
    when(conf.isEnabled()).thenReturn(true);

    boolean shouldExecute = scmActivitySensor.shouldExecuteOnProject(project);

    assertThat(shouldExecute).isTrue();
  }
  @Test(timeout = 2000)
  public void should_check_url() {
    when(conf.getThreadCount()).thenReturn(1);
    when(conf.getUrl()).thenReturn("scm:url");

    scmActivitySensor.analyse(project, context);

    verify(urlChecker).check("scm:url");
  }
  @Test
  public void should_carry_on_after_error() {
    InputFile first = file("source.java");
    InputFile second = file("UNKNOWN.java");
    when(conf.getThreadCount()).thenReturn(1);
    fs.add(first);
    fs.add(second);
    when(context.getResource(any(org.sonar.api.resources.File.class))).thenReturn(file);
    when(blameVersionSelector.detect(file, first, context)).thenThrow(new RuntimeException("BUG"));
    when(blameVersionSelector.detect(file, second, context)).thenReturn(measureUpdate);

    scmActivitySensor.analyse(project, context);

    verify(measureUpdate).execute(timeMachine, context);
  }
  @Test
  public void should_execute_measure_update_for_known_files() {
    InputFile source = file("source.java");
    InputFile test = file("UNKNOWN.java");
    when(conf.getThreadCount()).thenReturn(1);
    fs.add(source);
    fs.add(test);
    when(blameVersionSelector.detect(
            any(org.sonar.api.resources.File.class), eq(source), eq(context)))
        .thenReturn(measureUpdate);
    when(context.getResource(any(org.sonar.api.resources.File.class)))
        .thenReturn(file)
        .thenReturn(null);
    scmActivitySensor.analyse(project, context);

    verify(measureUpdate, only()).execute(timeMachine, context);
  }
  @Test
  public void should_generate_metrics() {
    List<Metric> metrics = scmActivitySensor.generatesMetrics();

    assertThat(metrics).hasSize(3);
  }
  @Test
  public void should_have_debug_name() {
    String debugName = scmActivitySensor.toString();

    assertThat(debugName).isEqualTo("ScmActivitySensor");
  }