Search in sources :

Example 46 with FakeRequest

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

the class BulkTest method cachesJsonData.

/**
 * Bulk can cache JSON data.
 * @throws Exception If some problem inside
 */
@Test
public void cachesJsonData() throws Exception {
    final Comment origin = Mockito.mock(Comment.class);
    final Request request = new FakeRequest().withBody("[{\"body\": \"hey you\"}]");
    final Iterable<Comment> comments = new Bulk<Comment>(new RtPagination<Comment>(request, new RtValuePagination.Mapping<Comment, JsonObject>() {

        @Override
        public Comment map(final JsonObject object) {
            return origin;
        }
    }));
    final Comment comment = comments.iterator().next();
    MatcherAssert.assertThat(new Comment.Smart(comment).body(), Matchers.equalTo("hey you"));
    comment.number();
    Mockito.verify(origin).number();
    Mockito.verify(origin, Mockito.never()).json();
}
Also used : Request(com.jcabi.http.Request) FakeRequest(com.jcabi.http.request.FakeRequest) JsonObject(javax.json.JsonObject) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 47 with FakeRequest

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

the class CommitsComparisonTest method fetchesCommits.

/**
 * CommitsComparison.Smart can fetch commits.
 * @throws Exception If some problem inside
 */
@Test
public void fetchesCommits() throws Exception {
    final String sha = "6dcb09b5b57875f334f61aebed695e2e4193db50";
    final CommitsComparison.Smart comparison = new CommitsComparison.Smart(new RtCommitsComparison(new FakeRequest().withBody(Json.createObjectBuilder().add("base_commit", Json.createObjectBuilder()).add("commits", Json.createArrayBuilder().add(Json.createObjectBuilder().add("sha", sha))).add("files", Json.createArrayBuilder()).build().toString()), CommitsComparisonTest.repo(), "6dcb09b5b57875f334f61aebed695e2e4193db51", "6dcb09b5b57875f334f61aebed695e2e4193db52"));
    MatcherAssert.assertThat(comparison.commits().iterator().next().sha(), Matchers.equalTo(sha));
}
Also used : FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 48 with FakeRequest

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

the class CommitsComparisonTest method fetchesFiles.

/**
 * CommitsComparison.Smart can fetch files.
 * @throws Exception If some problem inside
 */
@Test
public void fetchesFiles() throws Exception {
    final String filename = "file.txt";
    final CommitsComparison.Smart comparison = new CommitsComparison.Smart(new RtCommitsComparison(new FakeRequest().withBody(Json.createObjectBuilder().add("base_commit", Json.createObjectBuilder()).add("commits", Json.createArrayBuilder()).add("files", Json.createArrayBuilder().add(Json.createObjectBuilder().add("filename", filename))).build().toString()), CommitsComparisonTest.repo(), "6dcb09b5b57875f334f61aebed695e2e4193db53", "6dcb09b5b57875f334f61aebed695e2e4193db54"));
    MatcherAssert.assertThat(new FileChange.Smart(comparison.files().iterator().next()).filename(), Matchers.equalTo(filename));
}
Also used : FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 49 with FakeRequest

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

the class RtOrganizationTest method canCompareInstances.

/**
 * RtOrganization should be able to compare instances of each other.
 *
 * @throws Exception if a problem occurs.
 */
@Test
public void canCompareInstances() throws Exception {
    final RtOrganization less = new RtOrganization(new MkGithub(), new FakeRequest(), "abc");
    final RtOrganization greater = new RtOrganization(new MkGithub(), new FakeRequest(), "def");
    MatcherAssert.assertThat(less.compareTo(greater), Matchers.lessThan(0));
    MatcherAssert.assertThat(greater.compareTo(less), Matchers.greaterThan(0));
    MatcherAssert.assertThat(less.compareTo(less), Matchers.equalTo(0));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) FakeRequest(com.jcabi.http.request.FakeRequest) Test(org.junit.Test)

Example 50 with FakeRequest

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

the class RtPullCommentTest method canCompareInstances.

/**
 * RtPullComment should be able to compare different instances.
 * @throws Exception If a problem occurs.
 */
@Test
public void canCompareInstances() throws Exception {
    final Pull pull = Mockito.mock(Pull.class);
    Mockito.doReturn(new MkGithub().randomRepo()).when(pull).repo();
    final RtPullComment less = new RtPullComment(new FakeRequest(), pull, 1);
    final RtPullComment greater = new RtPullComment(new FakeRequest(), pull, 2);
    MatcherAssert.assertThat(less.compareTo(greater), Matchers.lessThan(0));
    MatcherAssert.assertThat(greater.compareTo(less), Matchers.greaterThan(0));
    MatcherAssert.assertThat(less.compareTo(less), Matchers.equalTo(0));
}
Also used : MkGithub(com.jcabi.github.mock.MkGithub) 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