-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
review comments + basic test coverage
- Loading branch information
1 parent
09be2d7
commit 6e098cf
Showing
15 changed files
with
153 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/test/java/pl/touk/sputnik/connector/github/GithubFacadeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package pl.touk.sputnik.connector.github; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.jcabi.github.*; | ||
import com.jcabi.immutable.Array; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Answers; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import pl.touk.sputnik.configuration.Configuration; | ||
import pl.touk.sputnik.configuration.ConfigurationSetup; | ||
import pl.touk.sputnik.connector.FacadeConfigUtil; | ||
import pl.touk.sputnik.review.*; | ||
|
||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Matchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class GithubFacadeTest { | ||
|
||
private static Integer SOME_PULL_REQUEST_ID = 12314; | ||
private static String SOME_REPOSITORY = "repo"; | ||
private static String SOME_PROJECT = "proj"; | ||
|
||
private static final Map<String, String> GITHUB_PATCHSET_MAP = ImmutableMap.of( | ||
"cli.pullRequestId", SOME_PULL_REQUEST_ID.toString(), | ||
"connector.repository", SOME_REPOSITORY, | ||
"connector.owner", SOME_PROJECT | ||
); | ||
|
||
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | ||
private Repo repo; | ||
|
||
@Mock(answer = Answers.RETURNS_DEEP_STUBS) | ||
private Pull pull; | ||
|
||
@Mock | ||
private Commit commit; | ||
|
||
@Mock | ||
private Commits commits; | ||
|
||
@Mock | ||
private Statuses statuses; | ||
|
||
private GithubFacade githubFacade; | ||
private Configuration config; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
when(repo.pulls().get(SOME_PULL_REQUEST_ID)).thenReturn(pull); | ||
when(pull.commits()).thenReturn(pullCommits()); | ||
when(pull.repo().git().commits()).thenReturn(commits); | ||
|
||
config = new ConfigurationSetup().setUp(FacadeConfigUtil.getHttpConfig("github"), GITHUB_PATCHSET_MAP); | ||
githubFacade = new GithubFacade(repo, new GithubPatchset(SOME_PULL_REQUEST_ID, projectPath())); | ||
} | ||
|
||
@Test | ||
public void shouldGetChangeInfo() throws Exception { | ||
when(pull.files()).thenReturn(pullFiles()); | ||
|
||
List<ReviewFile> files = githubFacade.listFiles(); | ||
|
||
assertThat(files).extracting("reviewFilename").containsOnly("1.java"); | ||
} | ||
|
||
@Test | ||
public void shouldAddIssue() throws Exception { | ||
when(commit.sha()).thenReturn("sha1"); | ||
when(commits.statuses("sha1")).thenReturn(statuses); | ||
|
||
String filename = "src/main/java/Main.java"; | ||
Review review = new Review(ImmutableList.of(new ReviewFile(filename)), ReviewFormatterFactory.get(config)); | ||
review.addError("checkstyle", new Violation(filename, 1, "error message", Severity.ERROR)); | ||
review.getMessages().add("Total 1 violations found"); | ||
|
||
githubFacade.setReview(review); | ||
|
||
verify(statuses).create(any(Statuses.StatusCreate.class)); | ||
} | ||
|
||
private Iterable<Commit> pullCommits() { | ||
return new Array<>(commit); | ||
} | ||
|
||
|
||
private List<JsonObject> pullFiles() { | ||
return Json.createArrayBuilder().add(Json.createObjectBuilder().add("filename", "1.java").build()).build().getValuesAs(JsonObject.class); | ||
} | ||
|
||
private String projectPath() { | ||
return String.format("%s/%s", SOME_PROJECT, SOME_REPOSITORY); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[ | ||
{ | ||
"sha": "d8bb2fc90f4d8b15d5fcfc9869df04aea5124813", | ||
"filename": "src/main/java/TestFile.java", | ||
"status": "modified", | ||
"additions": 2, | ||
"deletions": 1, | ||
"changes": 3, | ||
"blob_url": "https://github.com/pjagielski/sputnik-test/blob/ce66cc07c1dabf4f8b76a3181e39a1bb339244ae/src/main/java/TestFile.java", | ||
"raw_url": "https://github.com/pjagielski/sputnik-test/raw/ce66cc07c1dabf4f8b76a3181e39a1bb339244ae/src/main/java/TestFile.java", | ||
"contents_url": "https://api.github.com/repos/pjagielski/sputnik-test/contents/src/main/java/TestFile.java?ref=ce66cc07c1dabf4f8b76a3181e39a1bb339244ae", | ||
"patch": "@@ -7,8 +7,9 @@ private static void incorrectAssignmentInIfCondition() {\n boolean value = false;\n if (value = true) {\n //do Something\n+ value = false;\n } else {\n- //else Do Something\n+ //else Do Something 123\n }\n }\n }" | ||
}, | ||
{ | ||
"sha": "dc7ca1de3414e87ca773d62d54287fe8c414316e", | ||
"filename": "src/main/java/TestFile2.java", | ||
"status": "added", | ||
"additions": 13, | ||
"deletions": 0, | ||
"changes": 13, | ||
"blob_url": "https://github.com/pjagielski/sputnik-test/blob/ce66cc07c1dabf4f8b76a3181e39a1bb339244ae/src/main/java/TestFile2.java", | ||
"raw_url": "https://github.com/pjagielski/sputnik-test/raw/ce66cc07c1dabf4f8b76a3181e39a1bb339244ae/src/main/java/TestFile2.java", | ||
"contents_url": "https://api.github.com/repos/pjagielski/sputnik-test/contents/src/main/java/TestFile2.java?ref=ce66cc07c1dabf4f8b76a3181e39a1bb339244ae", | ||
"patch": "@@ -0,0 +1,13 @@\n+class TestFile2 {\n+ public String foo() {\n+ return \"bar\";\n+ }\n+\n+ private static void incorrectAssignmentInIfCondition() {\n+ boolean value = false;\n+ if (value = true) {\n+ //do Something\n+ value = false;\n+ }\n+ }\n+}" | ||
} | ||
] |