1
2
3
4
5 package com.jcabi.github;
6
7 import java.io.IOException;
8 import java.util.Collections;
9 import org.hamcrest.MatcherAssert;
10 import org.hamcrest.Matchers;
11 import org.junit.jupiter.api.Test;
12
13
14
15
16
17 @OAuthScope(OAuthScope.Scope.USER_EMAIL)
18 final class RtUserEmailsITCase {
19
20 @Test
21 void fetchesEmails() throws IOException {
22 MatcherAssert.assertThat(
23 "Collection is not empty",
24 RtUserEmailsITCase.userEmails().iterate(),
25 Matchers.not(Matchers.emptyIterableOf(String.class))
26 );
27 }
28
29
30
31
32
33 @Test
34 void addsEmails() throws IOException {
35 final String email = "test@mailtothis.com";
36 final UserEmails emails = RtUserEmailsITCase.userEmails();
37 try {
38 MatcherAssert.assertThat(
39 "Collection does not contain expected item",
40 emails.add(Collections.singletonList(email)),
41 Matchers.hasItem(email)
42 );
43 MatcherAssert.assertThat(
44 "Collection does not contain expected item", emails.iterate(), Matchers.hasItem(email)
45 );
46 } finally {
47 emails.remove(Collections.singletonList(email));
48 }
49 }
50
51
52
53
54
55 @Test
56 void removesEmails() throws IOException {
57 final String email = "test1@mailtothis.com";
58 final UserEmails emails = RtUserEmailsITCase.userEmails();
59 emails.add(Collections.singletonList(email));
60 try {
61 MatcherAssert.assertThat(
62 "Collection does not contain expected item", emails.iterate(), Matchers.hasItem(email)
63 );
64 } finally {
65 emails.remove(Collections.singletonList(email));
66 }
67 MatcherAssert.assertThat(
68 "Collection does not contain expected item",
69 emails.iterate(), Matchers.not(Matchers.hasItem(email))
70 );
71 }
72
73
74
75
76
77 private static UserEmails userEmails() {
78 return GitHubIT.connect().users().self().emails();
79 }
80
81 }