Skip to content

Commit

Permalink
Issue jcabi#923 Factor out repo creation in test
Browse files Browse the repository at this point in the history
  • Loading branch information
longtimeago committed Dec 19, 2014
1 parent 72ff7a7 commit 2125cfb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/jcabi/github/RtRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* @version $Id$
* @since 0.1
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
* @checkstyle ClassFanOutComplexity (5 lines)
* @checkstyle ClassFanOutComplexity (10 lines)
* @todo #923 Let's implement RtRepo.languages().
* Now it returns empty iterable but should return list of repo languages.
* Uncomment test RtRepoTest.iteratesLanguages() when done.
Expand Down
112 changes: 47 additions & 65 deletions src/test/java/com/jcabi/github/RtRepoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ public void iteratesEvents() throws Exception {
.build().toString()
)
).start();
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new ApacheRequest(container.home()),
new Coordinates.Simple("octocat", "master")
final Repo repo = RtRepoTest.repo(
new ApacheRequest(container.home())
);
MatcherAssert.assertThat(
repo.events(),
Expand All @@ -88,10 +86,8 @@ public void iteratesEvents() throws Exception {
*/
@Test
public void fetchesLabels() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("jeff", "jeff-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.labels(),
Expand All @@ -106,10 +102,8 @@ public void fetchesLabels() throws Exception {
*/
@Test
public void fetchesIssues() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("mark", "mark-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.issues(),
Expand All @@ -124,10 +118,8 @@ public void fetchesIssues() throws Exception {
*/
@Test
public void fetchesPulls() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("kendy", "kendy-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.pulls(),
Expand All @@ -142,10 +134,8 @@ public void fetchesPulls() throws Exception {
*/
@Test
public void fetchHooks() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("paul", "paul-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.hooks(),
Expand All @@ -160,10 +150,8 @@ public void fetchHooks() throws Exception {
*/
@Test
public void fetchKeys() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("andres", "andres-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.keys(),
Expand All @@ -178,10 +166,8 @@ public void fetchKeys() throws Exception {
*/
@Test
public void fetchReleases() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("phil", "phil-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.releases(),
Expand All @@ -196,10 +182,8 @@ public void fetchReleases() throws Exception {
*/
@Test
public void fetchContents() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("andres-contents", "contents-branch")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(
repo.contents(),
Expand Down Expand Up @@ -238,12 +222,10 @@ public void executePatchRequest() throws Exception {
event(Event.ASSIGNED).toString()
)
).start();
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new ApacheRequest(container.home()),
new Coordinates.Simple("test", "test-branch")
final Repo repo = RtRepoTest.repo(
new ApacheRequest(container.home())
);
repo.patch(event(Event.ASSIGNED));
repo.patch(RtRepoTest.event(Event.ASSIGNED));
MatcherAssert.assertThat(
container.take().method(),
Matchers.equalTo(Request.PATCH)
Expand All @@ -258,16 +240,14 @@ public void executePatchRequest() throws Exception {
*/
@Test
public void describeAsJson() throws Exception {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
final Repo repo = RtRepoTest.repo(
new FakeRequest().withBody(
Json.createObjectBuilder()
.add("full_name", "octocat/Hello-World")
.add("fork", true)
.build()
.toString()
),
new Coordinates.Simple("oct", "oct-branch")
)
);
MatcherAssert.assertThat(
repo.json().toString(),
Expand All @@ -282,22 +262,19 @@ public void describeAsJson() throws Exception {
*/
@Test
public void fetchCommits() {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("testuser", "testrepo")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(repo.commits(), Matchers.notNullValue());
}

/**
* RtRepo can fetch Git.
*/
@Test
public void fetchesGit() {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("gituser", "gitrepo")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(repo.git(), Matchers.notNullValue());
}
Expand All @@ -307,10 +284,8 @@ public void fetchesGit() {
*/
@Test
public void fetchStars() {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("testuser2", "testrepo2")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(repo.stars(), Matchers.notNullValue());
}
Expand All @@ -320,10 +295,8 @@ public void fetchStars() {
*/
@Test
public void fetchNotifications() {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("testnuser", "testnrepos")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(repo.notifications(), Matchers.notNullValue());
}
Expand All @@ -333,10 +306,8 @@ public void fetchNotifications() {
*/
@Test
public void fetchLanguages() {
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new FakeRequest(),
new Coordinates.Simple("testluser", "testlrepo")
final Repo repo = RtRepoTest.repo(
new FakeRequest()
);
MatcherAssert.assertThat(repo.languages(), Matchers.notNullValue());
}
Expand All @@ -360,10 +331,8 @@ public void iteratesLanguages() throws Exception {
.build().toString()
)
).start();
final Repo repo = new RtRepo(
Mockito.mock(Github.class),
new ApacheRequest(container.home()),
new Coordinates.Simple("testluser", "testlrepo")
final Repo repo = RtRepoTest.repo(
new ApacheRequest(container.home())
);
try {
final Iterator<Language> iter = repo.languages().iterator();
Expand Down Expand Up @@ -404,4 +373,17 @@ private static JsonObject event(final String event) throws Exception {
.add("event", event)
.build();
}

/**
* Create test Repo.
* @param request Request
* @return Repo
*/
private static Repo repo(final Request request) {
return new RtRepo(
Mockito.mock(Github.class),
request,
new Coordinates.Simple("testuser", "testrepo")
);
}
}

0 comments on commit 2125cfb

Please sign in to comment.