1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 package com.jcabi.github;
31
32 import com.jcabi.github.OAuthScope.Scope;
33 import com.jcabi.immutable.ArrayMap;
34 import java.util.Date;
35 import java.util.EnumMap;
36 import java.util.HashSet;
37 import java.util.Set;
38 import org.hamcrest.MatcherAssert;
39 import org.hamcrest.Matchers;
40 import org.junit.AfterClass;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43
44
45
46
47
48
49 @OAuthScope(Scope.REPO)
50 public final class RtIssuesITCase {
51
52
53
54 private static Repos repos;
55
56
57
58
59 private static Repo repo;
60
61
62
63
64
65 @BeforeClass
66 public static void setUp() throws Exception {
67 final Github github = new GithubIT().connect();
68 repos = github.repos();
69 repo = new RepoRule().repo(repos);
70 }
71
72
73
74
75
76 @AfterClass
77 public static void tearDown() throws Exception {
78 if (repos != null && repo != null) {
79 repos.remove(repo.coordinates());
80 }
81 }
82
83
84
85
86
87 @Test
88 public void iteratesIssues() throws Exception {
89 final Iterable<Issue.Smart> issues = new Smarts<>(
90 new Bulk<>(
91 repo.issues().iterate(
92 new ArrayMap<String, String>().with("sort", "comments")
93 )
94 )
95 );
96 for (final Issue.Smart issue : issues) {
97 MatcherAssert.assertThat(
98 issue.title(),
99 Matchers.notNullValue()
100 );
101 }
102 }
103
104
105
106
107
108 @Test
109 public void searchesIssues() throws Exception {
110 final String targetLabel = "bug";
111 final EnumMap<Issues.Qualifier, String> qualifiers =
112 new EnumMap<>(Issues.Qualifier.class);
113 qualifiers.put(Issues.Qualifier.LABELS, targetLabel);
114 final Iterable<Issue.Smart> issues = new Smarts<>(
115 new Bulk<>(
116 repo.issues().search(
117 Issues.Sort.UPDATED,
118 Search.Order.ASC,
119 qualifiers
120 )
121 )
122 );
123 Date prevUpdated = null;
124 final Set<String> labelNames = new HashSet<>();
125 for (final Issue.Smart issue : issues) {
126 MatcherAssert.assertThat(
127 issue.title(),
128 Matchers.notNullValue()
129 );
130 if (prevUpdated != null) {
131 MatcherAssert.assertThat(
132 issue.updatedAt(),
133 Matchers.lessThanOrEqualTo(prevUpdated)
134 );
135 }
136 prevUpdated = issue.updatedAt();
137 labelNames.clear();
138 for (final Label label : issue.roLabels().iterate()) {
139 labelNames.add(label.name());
140 }
141 MatcherAssert.assertThat(
142 labelNames,
143 Matchers.contains(targetLabel)
144 );
145 }
146 }
147 }