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.mock;
31
32 import com.jcabi.github.Event;
33 import com.jcabi.github.Issue;
34 import com.jcabi.github.IssueLabels;
35 import com.jcabi.github.Label;
36 import com.jcabi.github.Repo;
37 import java.util.Collections;
38 import java.util.Iterator;
39 import org.hamcrest.MatcherAssert;
40 import org.hamcrest.Matchers;
41 import org.junit.Test;
42
43
44
45
46
47
48 public final class MkIssueLabelsTest {
49
50
51
52 private static final String USER = "jeff";
53
54
55
56
57
58 @Test
59 public void iteratesIssues() throws Exception {
60 final Repo repo = new MkGithub().randomRepo();
61 final String name = "bug";
62 repo.labels().create(name, "c0c0c0");
63 final Issue issue = repo.issues().create("title", "body");
64 issue.labels().add(Collections.singletonList(name));
65 MatcherAssert.assertThat(
66 issue.labels().iterate(),
67 Matchers.<Label>iterableWithSize(1)
68 );
69 }
70
71
72
73
74
75 @Test
76 public void createsLabelsThroughDecorator() throws Exception {
77 final Repo repo = new MkGithub().randomRepo();
78 final Issue issue = repo.issues().create("how are you?", "");
79 final String name = "task";
80 new IssueLabels.Smart(issue.labels()).addIfAbsent(name, "f0f0f0");
81 MatcherAssert.assertThat(
82 issue.labels().iterate(),
83 Matchers.<Label>iterableWithSize(1)
84 );
85 }
86
87
88
89
90
91 @Test
92 public void addingLabelGeneratesEvent() throws Exception {
93 final Repo repo = new MkGithub().randomRepo();
94 final String name = "confirmed";
95 repo.labels().create(name, "663399");
96 final Issue issue = repo.issues().create("Titular", "Corpus");
97 issue.labels().add(Collections.singletonList(name));
98 MatcherAssert.assertThat(
99 issue.events(),
100 Matchers.<Event>iterableWithSize(1)
101 );
102 final Event.Smart labeled = new Event.Smart(
103 issue.events().iterator().next()
104 );
105 MatcherAssert.assertThat(
106 labeled.type(),
107 Matchers.equalTo(Event.LABELED)
108 );
109 MatcherAssert.assertThat(
110 labeled.author().login(),
111 Matchers.equalTo(USER)
112 );
113 MatcherAssert.assertThat(
114 labeled.repo(),
115 Matchers.equalTo(repo)
116 );
117 MatcherAssert.assertThat(
118 labeled.label().get().name(),
119 Matchers.equalTo(name)
120 );
121 }
122
123
124
125
126
127 @Test
128 public void removingLabelGeneratesEvent() throws Exception {
129 final Repo repo = new MkGithub().randomRepo();
130 final String name = "invalid";
131 repo.labels().create(name, "ee82ee");
132 final Issue issue = repo.issues().create("Rewrite", "Sound good?");
133 issue.labels().add(Collections.singletonList(name));
134 issue.labels().remove(name);
135 MatcherAssert.assertThat(
136 issue.events(),
137 Matchers.<Event>iterableWithSize(2)
138 );
139 final Iterator<Event> events = issue.events().iterator();
140 events.next();
141 final Event.Smart unlabeled = new Event.Smart(events.next());
142 MatcherAssert.assertThat(
143 unlabeled.type(),
144 Matchers.equalTo(Event.UNLABELED)
145 );
146 MatcherAssert.assertThat(
147 unlabeled.author().login(),
148 Matchers.equalTo(USER)
149 );
150 MatcherAssert.assertThat(
151 unlabeled.repo(),
152 Matchers.equalTo(repo)
153 );
154 MatcherAssert.assertThat(
155 unlabeled.label().get().name(),
156 Matchers.equalTo(name)
157 );
158 }
159 }