1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.aspects.Immutable;
8 import com.jcabi.http.mock.MkAnswer;
9 import com.jcabi.http.mock.MkContainer;
10 import com.jcabi.http.mock.MkGrizzlyContainer;
11 import com.jcabi.http.request.FakeRequest;
12 import com.jcabi.http.request.JdkRequest;
13 import jakarta.json.Json;
14 import java.io.IOException;
15 import java.net.HttpURLConnection;
16 import org.hamcrest.MatcherAssert;
17 import org.hamcrest.Matchers;
18 import org.junit.jupiter.api.Test;
19 import org.junit.jupiter.api.extension.ExtendWith;
20
21
22
23
24
25
26 @Immutable
27 @ExtendWith(RandomPort.class)
28 final class RtGitignoresTest {
29
30
31
32
33 @Test
34 void iterateTemplateNames() throws IOException {
35 try (
36 MkContainer container = new MkGrizzlyContainer().next(
37 new MkAnswer.Simple(
38 HttpURLConnection.HTTP_OK,
39 Json.createArrayBuilder()
40 .add("C")
41 .add("Java")
42 .build()
43 .toString()
44 )
45 ).start(RandomPort.port())
46 ) {
47 final RtGitignores gitignores = new RtGitignores(
48 new RtGitHub(new JdkRequest(container.home()))
49 );
50 MatcherAssert.assertThat(
51 "Collection size is incorrect",
52 gitignores.iterate(),
53 Matchers.iterableWithSize(2)
54 );
55 container.stop();
56 }
57 }
58
59 @Test
60 void getRawTemplateByName() throws IOException {
61 final RtGitignores gitignores = new RtGitignores(
62 new RtGitHub(new FakeRequest().withBody("# Object files"))
63 );
64 MatcherAssert.assertThat(
65 "String does not start with expected value",
66 gitignores.template("C#"),
67 Matchers.startsWith("# Object")
68 );
69 }
70
71 }