@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 shouldOverrideMavenUrl() { when(mavenConf.getUrl()).thenReturn("scm:svn:http:readonly"); settings.setProperty(ScmActivityPlugin.URL, "scm:svn:http:override"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:http:override"); }
@Test public void shouldNotGetMavenDeveloperUrlIfNoCredentials() { when(mavenConf.getDeveloperUrl()).thenReturn("scm:svn:https:writable"); when(mavenConf.getUrl()).thenReturn("scm:svn:https:readonly"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:https:readonly"); }
@Test public void should_guess_by_default() { when(scmUrlGuess.guess()).thenReturn("scm:svn:guessed"); when(mavenConf.getUrl()).thenReturn("scm:svn:http:readonly"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:guessed"); }
@Test public void should_disable_guess_with_hidden_configuration() { settings.setProperty("sonar.scm.hidden.guess", false); when(scmUrlGuess.guess()).thenReturn("scm:svn:guessed"); when(mavenConf.getUrl()).thenReturn("scm:svn:http:readonly"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:http:readonly"); }
@Test public void should_guess_url_only_once() { when(scmUrlGuess.guess()).thenReturn("scm:svn:guessed"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:guessed"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:guessed"); verify(scmUrlGuess, times(1)).guess(); }
@Test public void should_execute() { when(conf.isEnabled()).thenReturn(true); boolean shouldExecute = scmActivitySensor.shouldExecuteOnProject(project); assertThat(shouldExecute).isTrue(); }
@Test public void should_not_execute_if_disabled() { when(conf.isEnabled()).thenReturn(false); boolean shouldExecute = scmActivitySensor.shouldExecuteOnProject(project); assertThat(shouldExecute).isFalse(); }
@Test public void shouldGetMavenDeveloperUrlIfCredentials() { when(mavenConf.getDeveloperUrl()).thenReturn("scm:svn:https:writable"); settings.setProperty(ScmActivityPlugin.USER, "godin"); settings.setProperty(ScmActivityPlugin.PASSWORD, "pass"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:https:writable"); }
@Test public void should_fail_on_invalid_thread_count() { settings.setProperty(ScmActivityPlugin.THREAD_COUNT, 0); exception.expect(SonarException.class); exception.expectMessage( "SCM Activity Plugin is configured to use [0] thread(s). The minimum is 1."); scmConfiguration.getThreadCount(); }
@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 shouldReturnPerforceClientSpec() { settings.setProperty(ScmActivityPlugin.PERFORCE_CLIENTSPEC_NAME, "myclientspec"); assertThat(scmConfiguration.getPerforceClientspecName()).isEqualTo("myclientspec"); }
@Test public void shouldGetMavenUrlIfNoDeveloperUrl() { when(mavenConf.getUrl()).thenReturn("scm:svn:http:readonly"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:http:readonly"); }
@Test public void should_guess_url_if_nothing_configured() { when(scmUrlGuess.guess()).thenReturn("scm:svn:guessed"); assertThat(scmConfiguration.getUrl()).isEqualTo("scm:svn:guessed"); }
@Test public void should_get_default_thread_count() { assertThat(scmConfiguration.getThreadCount()).isEqualTo(4); }
@Test public void should_use_single_thread() { settings.setProperty(ScmActivityPlugin.THREAD_COUNT, 1); assertThat(scmConfiguration.getThreadCount()).isEqualTo(1); }
@Test public void should_be_enabled_by_default() { assertThat(scmConfiguration.isEnabled()).isTrue(); }
@Test public void should_disable() { settings.setProperty(ScmActivityPlugin.ENABLED, false); assertThat(scmConfiguration.isEnabled()).isFalse(); }
@Test public void shouldReturnPassword() { settings.setProperty(ScmActivityPlugin.PASSWORD, "pass"); assertThat(scmConfiguration.getPassword()).isEqualTo("pass"); }
@Test public void shouldReturnUrlFromConfiguration() { settings.setProperty(ScmActivityPlugin.URL, "http://test"); assertThat(scmConfiguration.getUrl()).isEqualTo("http://test"); }
@Test public void shouldReturnUsername() { settings.setProperty(ScmActivityPlugin.USER, "godin"); assertThat(scmConfiguration.getUser()).isEqualTo("godin"); }
@Test public void should_accept_thread_count_too_high() { settings.setProperty(ScmActivityPlugin.THREAD_COUNT, 1000); assertThat(scmConfiguration.getThreadCount()).isEqualTo(1000); }
@Test public void should_get_maven_url_in_non_maven_environment() { scmConfiguration = new ScmConfiguration(settings, scmUrlGuess); assertThat(scmConfiguration.getUrl()).isNull(); }
@Test public void should_get_empty_scm_provider() { when(mavenConf.getUrl()).thenReturn(" "); assertThat(scmConfiguration.getScmProvider()).isNull(); }
@Test public void shouldGetScmProvider() { when(mavenConf.getUrl()).thenReturn("scm:svn:http:foo"); assertThat(scmConfiguration.getScmProvider()).isEqualTo("svn"); }