1
2
3
4
5 package com.jcabi.github.mock;
6
7 import com.jcabi.github.UserEmails;
8 import java.io.IOException;
9 import java.util.Arrays;
10 import java.util.Collections;
11 import org.hamcrest.MatcherAssert;
12 import org.hamcrest.Matchers;
13 import org.junit.jupiter.api.Test;
14
15
16
17
18
19 final class MkUserEmailsTest {
20
21 @Test
22 void canAddEmails() throws IOException {
23 final UserEmails emails = new MkGitHub().users().add("john").emails();
24 final String email = "john@nowhere.com";
25 final Iterable<String> added = emails.add(
26 Collections.singleton(email)
27 );
28 MatcherAssert.assertThat(
29 "Collection size is incorrect",
30 added,
31 Matchers.allOf(
32 Matchers.iterableWithSize(1),
33 Matchers.hasItems(email)
34 )
35 );
36 }
37
38 @Test
39 void canRemoveEmails() throws IOException {
40 final UserEmails emails = new MkGitHub().users().add("joe").emails();
41 final String removed = "joe@nowhere.com";
42 final String retained = "joseph@somewhere.net";
43 emails.add(
44 Arrays.asList(
45 new String[]{removed, retained}
46 )
47 );
48 emails.remove(Collections.singleton(removed));
49 MatcherAssert.assertThat(
50 "Collection size is incorrect",
51 emails.iterate(),
52 Matchers.allOf(
53 Matchers.iterableWithSize(1),
54 Matchers.hasItems(retained),
55 Matchers.not(Matchers.hasItems(removed))
56 )
57 );
58 }
59
60 @Test
61 void canIterateEmails() throws IOException {
62 final UserEmails emails = new MkGitHub().users().add("matt").emails();
63 final String[] added = {
64 "matt@none.org",
65 "matthew@somewhere.net",
66 };
67 emails.add(Arrays.asList(added));
68 MatcherAssert.assertThat(
69 "Collection size is incorrect",
70 emails.iterate(),
71 Matchers.allOf(
72 Matchers.iterableWithSize(2),
73 Matchers.hasItems(added)
74 )
75 );
76 }
77
78 @Test
79 void canRepresentAsJson() throws IOException {
80 final UserEmails emails = new MkGitHub().users().add("jeff").emails();
81 final String email = "jeff@something.net";
82 emails.add(Collections.singleton(email));
83 MatcherAssert.assertThat(
84 "Values are not equal",
85 emails.json().getString("email"),
86 Matchers.is(email)
87 );
88 }
89
90 }