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.google.common.base.Optional;
33 import com.jcabi.github.Event;
34 import com.jcabi.github.Label;
35 import com.jcabi.github.Repo;
36 import com.jcabi.github.Repos;
37 import org.hamcrest.MatcherAssert;
38 import org.hamcrest.Matchers;
39 import org.junit.Test;
40
41
42
43
44
45
46 public final class MkEventTest {
47
48
49
50
51 @Test
52 public void canGetCreatedAt() throws Exception {
53 final MkStorage storage = new MkStorage.InFile();
54 final String user = "test_user";
55 final Repo repo = new MkGithub(storage, user).randomRepo();
56 final MkIssueEvents events = (MkIssueEvents) repo.issueEvents();
57 final int eventnum = events.create(
58 "test_type",
59 1,
60 user,
61 Optional.of("test_label")
62 ).number();
63 MatcherAssert.assertThat(
64 new MkEvent(
65 storage,
66 user,
67 repo.coordinates(),
68 eventnum
69 )
70 .json().getString("created_at"),
71 Matchers.notNullValue()
72 );
73 }
74
75
76
77
78
79 @Test
80 public void canGetPresentLabel() throws Exception {
81 final MkStorage storage = new MkStorage.InFile();
82 final String user = "ken";
83 final Repo repo = new MkGithub(storage, user).repos().create(
84 new Repos.RepoCreate("foo", false)
85 );
86 final MkIssueEvents events = (MkIssueEvents) repo.issueEvents();
87 final String label = "problem";
88 final int num = events.create(
89 Event.LABELED,
90 1,
91 user,
92 Optional.of(label)
93 ).number();
94 MatcherAssert.assertThat(
95 new Event.Smart(
96 new MkEvent(
97 storage,
98 user,
99 repo.coordinates(),
100 num
101 )
102 ).label().get().name(),
103 Matchers.equalTo(label)
104 );
105 }
106
107
108
109
110
111 @Test
112 public void canGetAbsentLabel() throws Exception {
113 final MkStorage storage = new MkStorage.InFile();
114 final String user = "barbie";
115 final Repo repo = new MkGithub(storage, user).repos().create(
116 new Repos.RepoCreate("bar", false)
117 );
118 final int num = ((MkIssueEvents) repo.issueEvents()).create(
119 Event.LABELED,
120 1,
121 user,
122 Optional.<String>absent()
123 ).number();
124 MatcherAssert.assertThat(
125 new Event.Smart(
126 new MkEvent(
127 storage,
128 user,
129 repo.coordinates(),
130 num
131 )
132 ).label(),
133 Matchers.equalTo(Optional.<Label>absent())
134 );
135 }
136 }