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.Notification;
33 import org.hamcrest.MatcherAssert;
34 import org.hamcrest.Matchers;
35 import org.junit.Test;
36 import org.xembly.Directives;
37
38
39
40
41
42
43
44
45 @SuppressWarnings("PMD.AvoidDuplicateLiterals")
46 public final class MkNotificationsTest {
47
48
49
50
51
52 @Test
53 public void fetchesEmptyListOfNotifications() throws Exception {
54 MatcherAssert.assertThat(
55 new MkNotifications(
56 new MkStorage.InFile(),
57 "notifications"
58 ).iterate(),
59 Matchers.emptyIterable()
60 );
61 }
62
63
64
65
66
67 @Test
68 public void fetchesNonEmptyListOfNotifications() throws Exception {
69 final MkStorage storage = new MkStorage.InFile();
70 storage.apply(
71 new Directives().xpath("/github")
72 .add("notifications")
73 .add("notification")
74 .add("id").set("1").up().up()
75 .add("notification")
76 .add("id").set("2").up().up()
77 .add("notification")
78 .add("id").set("3").up().up()
79 );
80 MatcherAssert.assertThat(
81 new MkNotifications(
82 storage,
83 "/github/notifications/notification"
84 ).iterate(),
85
86 Matchers.<Notification>iterableWithSize(3)
87 );
88 }
89
90
91
92
93
94 @Test
95 public void fetchesNotificationById() throws Exception {
96 final MkStorage storage = new MkStorage.InFile();
97 storage.apply(
98 new Directives().xpath("/github")
99 .add("notifications")
100 .add("notification")
101 .add("id").set("1").up().up()
102 .add("notification")
103 .add("id").set("2").up().up()
104 );
105 MatcherAssert.assertThat(
106 new MkNotifications(
107 storage,
108 "/github/notifications/notification"
109 ).get(2),
110 Matchers.notNullValue()
111 );
112 }
113
114
115
116
117
118 @Test(expected = IndexOutOfBoundsException.class)
119 public void cannotFetchNotificationByNonExistentId() throws Exception {
120 final MkStorage storage = new MkStorage.InFile();
121 storage.apply(
122 new Directives().xpath("/github")
123 .add("notifications")
124 .add("notification")
125 .add("id").set("1").up().up()
126 .add("notification")
127 .add("id").set("3").up().up()
128 );
129 MatcherAssert.assertThat(
130 new MkNotifications(
131 storage,
132 "/github/notifications/notification"
133 ).get(2),
134 Matchers.notNullValue()
135 );
136 }
137 }