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.UserEmails;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import org.hamcrest.MatcherAssert;
36 import org.hamcrest.Matchers;
37 import org.junit.Test;
38
39
40
41
42
43
44
45
46 public final class MkUserEmailsTest {
47
48
49
50
51
52
53 @Test
54 public void canAddEmails() throws Exception {
55 final UserEmails emails = new MkGithub().users().add("john").emails();
56 final String email = "john@nowhere.com";
57 final Iterable<String> added = emails.add(
58 Collections.singleton(email)
59 );
60 MatcherAssert.assertThat(
61 added,
62 Matchers.allOf(
63 Matchers.<String>iterableWithSize(1),
64 Matchers.hasItems(email)
65 )
66 );
67 }
68
69
70
71
72
73
74 @Test
75 public void canRemoveEmails() throws Exception {
76 final UserEmails emails = new MkGithub().users().add("joe").emails();
77 final String removed = "joe@nowhere.com";
78 final String retained = "joseph@somewhere.net";
79 emails.add(
80 Arrays.asList(
81 new String[]{removed, retained}
82 )
83 );
84 emails.remove(Collections.singleton(removed));
85 MatcherAssert.assertThat(
86 emails.iterate(),
87 Matchers.allOf(
88 Matchers.<String>iterableWithSize(1),
89 Matchers.hasItems(retained),
90 Matchers.not(Matchers.hasItems(removed))
91 )
92 );
93 }
94
95
96
97
98
99
100 @Test
101 public void canIterateEmails() throws Exception {
102 final UserEmails emails = new MkGithub().users().add("matt").emails();
103 final String[] added = new String[]{
104 "matt@none.org",
105 "matthew@somewhere.net",
106 };
107 emails.add(Arrays.asList(added));
108 MatcherAssert.assertThat(
109 emails.iterate(),
110 Matchers.allOf(
111 Matchers.<String>iterableWithSize(2),
112 Matchers.hasItems(added)
113 )
114 );
115 }
116
117
118
119
120
121
122 @Test
123 public void canRepresentAsJson() throws Exception {
124 final UserEmails emails = new MkGithub().users().add("jeff").emails();
125 final String email = "jeff@something.net";
126 emails.add(Collections.singleton(email));
127 MatcherAssert.assertThat(
128 emails.json().getString("email"),
129 Matchers.is(email)
130 );
131 }
132
133 }