1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.github.mock.MkGitHub;
8 import com.jcabi.http.request.FakeRequest;
9 import java.io.IOException;
10 import java.net.HttpURLConnection;
11 import org.hamcrest.MatcherAssert;
12 import org.hamcrest.Matchers;
13 import org.junit.jupiter.api.Test;
14 import org.mockito.Mockito;
15
16
17
18
19
20 final class RtReleaseAssetsTest {
21
22
23
24
25
26 @Test
27 void listReleaseAssets() throws Exception {
28 final ReleaseAssets assets = new RtReleaseAssets(
29 new FakeRequest().withStatus(HttpURLConnection.HTTP_OK)
30 .withBody("[{\"id\":1}, {\"id\":2}]"), RtReleaseAssetsTest.release()
31 );
32 MatcherAssert.assertThat(
33 "Collection size is incorrect",
34 assets.iterate(),
35 Matchers.iterableWithSize(2)
36 );
37 }
38
39
40
41
42
43 @Test
44 void uploadReleaseAsset() throws Exception {
45 final String body = "{\"id\":1}";
46 final ReleaseAssets assets = new RtReleaseAssets(
47 new FakeRequest().withStatus(HttpURLConnection.HTTP_CREATED)
48 .withBody(body),
49 RtReleaseAssetsTest.release()
50 );
51 MatcherAssert.assertThat(
52 "Values are not equal",
53 assets.upload(body.getBytes(), "text/plain", "hello.txt")
54 .number(),
55 Matchers.is(1)
56 );
57 }
58
59
60
61
62
63 @Test
64 void getReleaseAsset() throws Exception {
65 final ReleaseAssets assets = new RtReleaseAssets(
66 new FakeRequest().withStatus(HttpURLConnection.HTTP_OK)
67 .withBody("{\"id\":3}"),
68 RtReleaseAssetsTest.release()
69 );
70 MatcherAssert.assertThat(
71 "Values are not equal",
72 assets.get(3).number(),
73 Matchers.is(3)
74 );
75 }
76
77
78
79
80
81 private static Release release() throws IOException {
82 final Release release = Mockito.mock(Release.class);
83 final Repo repo = new MkGitHub("john").randomRepo();
84 Mockito.doReturn(repo).when(release).repo();
85 Mockito.doReturn(1).when(release).number();
86 return release;
87 }
88 }