Search in sources :

Example 26 with FakeRequest

use of com.jcabi.http.request.FakeRequest in project jcabi-github by jcabi.

the class RtUserTest method fetchesOrganizations.

/**
 * RtUser can fetch organizations.
 */
@Test
public void fetchesOrganizations() {
    final Github github = Mockito.mock(Github.class);
    Mockito.when(github.entry()).thenReturn(new FakeRequest());
    final User user = new RtUser(github, new FakeRequest());
    MatcherAssert.assertThat(user.organizations(), Matchers.notNullValue());
}
Also used : FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 27 with FakeRequest

use of com.jcabi.http.request.FakeRequest in project jcabi-github by jcabi.

the class RtCommitsComparisonTest method fetchesJson.

/**
 * RtCommitsComparison can fetch JSON.
 * @throws Exception If some problem inside
 * @checkstyle MultipleStringLiterals (75 lines)
 * @checkstyle ExecutableStatementCountCheck (75 lines)
 */
@Test
public void fetchesJson() throws Exception {
    final String sha = "fffffffffffffffffffffffffffffffffffffffe";
    final String filename = "bar/quux.txt";
    // @checkstyle MagicNumberCheck (3 lines)
    final int additions = 7;
    final int deletions = 2;
    final int changes = 9;
    final String patch = "some diff here";
    // @checkstyle LineLength (3 lines)
    final String bloburl = "https://api.jcabi-github.invalid/johndoe/my-repo/blob/fffffffffffffffffffffffffffffffffffffffe/bar/quux.txt";
    final String rawurl = "https://api.jcabi-github.invalid/johndoe/my-repo/raw/fffffffffffffffffffffffffffffffffffffffe/bar/quux.txt";
    final String contentsurl = "https://api.github.invalid/repos/johndoe/my-repo/contents/bar/quux.txt?ref=fffffffffffffffffffffffffffffffffffffffe";
    final CommitsComparison comparison = new RtCommitsComparison(new FakeRequest().withBody(Json.createObjectBuilder().add("base_commit", Json.createObjectBuilder()).add("commits", Json.createArrayBuilder()).add("files", Json.createArrayBuilder().add(Json.createObjectBuilder().add("sha", sha).add("filename", filename).add("status", "added").add("additions", additions).add("deletions", deletions).add("changes", changes).add("patch", patch).add("blob_url", bloburl).add("raw_url", rawurl).add("contents_url", contentsurl).build()).build()).build().toString()), RtCommitsComparisonTest.repo(), "6dcb09b5b57875f334f61aebed695e2e4193db51", "6dcb09b5b57875f334f61aebed695e2e4193db52");
    final JsonObject json = comparison.json();
    MatcherAssert.assertThat(json.getJsonObject("base_commit"), Matchers.notNullValue());
    MatcherAssert.assertThat(json.getJsonArray("commits"), Matchers.notNullValue());
    MatcherAssert.assertThat(comparison.files(), Matchers.<FileChange>iterableWithSize(1));
    final FileChange.Smart file = new FileChange.Smart(comparison.files().iterator().next());
    MatcherAssert.assertThat(file.sha(), Matchers.equalTo(sha));
    MatcherAssert.assertThat(file.filename(), Matchers.equalTo(filename));
    MatcherAssert.assertThat(file.additions(), Matchers.equalTo(additions));
    MatcherAssert.assertThat(file.deletions(), Matchers.equalTo(deletions));
    MatcherAssert.assertThat(file.changes(), Matchers.equalTo(changes));
    MatcherAssert.assertThat(file.status(), Matchers.equalTo(FileChange.Status.ADDED));
    MatcherAssert.assertThat(file.patch(), Matchers.equalTo(Optional.of(patch)));
}
Also used : JsonObject(javax.json.JsonObject) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 28 with FakeRequest

use of com.jcabi.http.request.FakeRequest in project jcabi-github by jcabi.

the class RtContentTest method canCompareInstances.

/**
 * RtContent should be able to compare different instances.
 *
 * @throws Exception when a problem occurs.
 */
@Test
public void canCompareInstances() throws Exception {
    final RtContent less = new RtContent(new FakeRequest(), this.repo(), "aaa");
    final RtContent greater = new RtContent(new FakeRequest(), this.repo(), "zzz");
    MatcherAssert.assertThat(less.compareTo(greater), Matchers.lessThan(0));
    MatcherAssert.assertThat(greater.compareTo(less), Matchers.greaterThan(0));
    MatcherAssert.assertThat(greater.compareTo(greater), Matchers.is(0));
}
Also used : FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 29 with FakeRequest

use of com.jcabi.http.request.FakeRequest in project jcabi-github by jcabi.

the class RtIssueTest method fetchesComments.

/**
 * RtIssue should be able to fetch its comments.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void fetchesComments() throws Exception {
    final RtIssue issue = new RtIssue(new FakeRequest(), this.repo(), 1);
    MatcherAssert.assertThat(issue.comments(), Matchers.notNullValue());
}
Also used : FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 30 with FakeRequest

use of com.jcabi.http.request.FakeRequest in project jcabi-github by jcabi.

the class RtIssueTest method fetchesEvents.

/**
 * RtIssue should be able to fetch its events.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void fetchesEvents() throws Exception {
    final RtIssue issue = new RtIssue(new FakeRequest(), this.repo(), 1);
    MatcherAssert.assertThat(issue.events(), Matchers.notNullValue());
}
Also used : FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Aggregations

FakeRequest (com.jcabi.http.request.FakeRequest)65 Test (org.junit.Test)65 MkGithub (com.jcabi.github.mock.MkGithub)9 JsonObject (javax.json.JsonObject)3 Request (com.jcabi.http.Request)2 ApacheRequest (com.jcabi.http.request.ApacheRequest)2 MkOrganization (com.jcabi.github.mock.MkOrganization)1 Response (com.jcabi.http.Response)1 MkContainer (com.jcabi.http.mock.MkContainer)1 MkGrizzlyContainer (com.jcabi.http.mock.MkGrizzlyContainer)1 JsonResponse (com.jcabi.http.response.JsonResponse)1