Skip to content
This repository has been archived by the owner on Apr 2, 2019. It is now read-only.

Commit

Permalink
SONARGITUB-14 Do not rely only on sonar.dryRun property since it was …
Browse files Browse the repository at this point in the history
…removed in 5.2
  • Loading branch information
henryju committed Oct 19, 2015
1 parent 88c8f29 commit 066032d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Expand Up @@ -55,8 +55,12 @@ public void build(Context context) {
}

private void checkMode() {
if (!settings.getBoolean(CoreProperties.DRY_RUN)) {
throw MessageException.of("The GitHub plugin is only intended to be used in preview mode. Please set '" + CoreProperties.ANALYSIS_MODE + "'.");
boolean isIssues = settings.getBoolean(CoreProperties.DRY_RUN) || CoreProperties.ANALYSIS_MODE_PREVIEW.equals(settings.getString(CoreProperties.ANALYSIS_MODE))
|| CoreProperties.ANALYSIS_MODE_INCREMENTAL.equals(settings.getString(CoreProperties.ANALYSIS_MODE))
// 5.2+
|| "issues".equals(settings.getString(CoreProperties.ANALYSIS_MODE));
if (!isIssues) {
throw MessageException.of("The GitHub plugin is only intended to be used in preview or issues mode. Please set '" + CoreProperties.ANALYSIS_MODE + "'.");
}

}
Expand Down
Expand Up @@ -66,19 +66,48 @@ public void shouldFailIfNotPreview() {
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");

thrown.expect(MessageException.class);
thrown.expectMessage("The GitHub plugin is only intended to be used in preview mode. Please set 'sonar.analysis.mode'.");
thrown.expectMessage("The GitHub plugin is only intended to be used in preview or issues mode. Please set 'sonar.analysis.mode'.");

pullRequestProjectBuilder.build(null);
}

@Test
public void shouldNotFailIfPreview() {
public void shouldNotFailIfDryRun() {
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
settings.setProperty(CoreProperties.DRY_RUN, "true");

pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));

verify(facade).init(eq(1), any(File.class));
}

@Test
public void shouldNotFailIfPreview() {
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
settings.setProperty(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_PREVIEW);

pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));

verify(facade).init(eq(1), any(File.class));
}

@Test
public void shouldNotFailIfIncremental() {
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
settings.setProperty(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_INCREMENTAL);

pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));

verify(facade).init(eq(1), any(File.class));
}

@Test
public void shouldNotFailIfIssues() {
settings.setProperty(GitHubPlugin.GITHUB_PULL_REQUEST, "1");
settings.setProperty(CoreProperties.ANALYSIS_MODE, "issues");

pullRequestProjectBuilder.build(mock(ProjectBuilder.Context.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)));

verify(facade).init(eq(1), any(File.class));
}
}

0 comments on commit 066032d

Please sign in to comment.