1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.User;
8 import com.jcabi.github.UserOrganizations;
9 import java.io.IOException;
10 import java.time.Instant;
11 import java.time.temporal.ChronoUnit;
12 import java.util.Date;
13 import org.hamcrest.MatcherAssert;
14 import org.hamcrest.Matchers;
15 import org.junit.jupiter.api.Test;
16 import org.xembly.Directives;
17
18
19
20
21
22
23 final class MkUserTest {
24
25
26
27
28
29 @Test
30 void testGetOrganizations() throws IOException {
31 final MkUser user = new MkUser(
32 new MkStorage.InFile(),
33 "orgTestIterate"
34 );
35 final UserOrganizations orgs = user.organizations();
36 MatcherAssert.assertThat(
37 "Value is null",
38 orgs,
39 Matchers.notNullValue()
40 );
41 }
42
43
44
45
46
47
48
49
50 @Test
51 void returnsNotifications() throws IOException {
52 MatcherAssert.assertThat(
53 "Value is null",
54 new MkUser(
55 new MkStorage.InFile(),
56 "notifications"
57 ).notifications(),
58 Matchers.notNullValue()
59 );
60 }
61
62
63
64
65
66
67 @Test
68 void marksNotificationsAsReadUpToDate() throws IOException {
69 final MkStorage storage = new MkStorage.InFile();
70 storage.apply(new Directives().xpath("/github").add("users"));
71 final User user = new MkUsers(storage, "joe").add("joe");
72 final Instant upto = Instant.now();
73 storage.apply(
74 new Directives()
75 .xpath("//notifications")
76 .add("notification")
77 .add("id").set(1).up()
78 .add("date").set(
79
80 upto.minus(30, ChronoUnit.MINUTES).toEpochMilli()
81 ).up()
82 .add("read").set(false).up()
83 .up()
84 .add("notification")
85 .add("id").set(2).up()
86 .add("date").set(
87
88 upto.plus(30, ChronoUnit.MINUTES).toEpochMilli()
89 ).up()
90 .add("read").set(false).up()
91 .up()
92 );
93 user.markAsRead(Date.from(upto));
94 MatcherAssert.assertThat(
95 "Values are not equal",
96 storage.xml().xpath("//notification[id = 1]/read/text()").get(0),
97 Matchers.is("true")
98 );
99 MatcherAssert.assertThat(
100 "Values are not equal",
101 storage.xml().xpath("//notification[id = 2]/read/text()").get(0),
102 Matchers.is("false")
103 );
104 }
105 }