View Javadoc
1   /**
2    * Copyright (c) 2013-2023, jcabi.com
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met: 1) Redistributions of source code must retain the above
8    * copyright notice, this list of conditions and the following
9    * disclaimer. 2) Redistributions in binary form must reproduce the above
10   * copyright notice, this list of conditions and the following
11   * disclaimer in the documentation and/or other materials provided
12   * with the distribution. 3) Neither the name of the jcabi.com nor
13   * the names of its contributors may be used to endorse or promote
14   * products derived from this software without specific prior written
15   * permission.
16   *
17   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19   * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20   * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21   * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22   * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23   * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26   * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28   * OF THE POSSIBILITY OF SUCH DAMAGE.
29   */
30  package com.jcabi.github;
31  
32  import com.jcabi.github.OAuthScope.Scope;
33  import java.util.Collections;
34  import org.hamcrest.MatcherAssert;
35  import org.hamcrest.Matchers;
36  import org.junit.Test;
37  
38  /**
39   * Test case for {@link RtUserEmails}.
40   * @author Alexander Sinyagin (sinyagin.alexander@gmail.com)
41   * @version $Id: 35039187dc0d5343570096de20de73485431c02e $
42   */
43  @OAuthScope(Scope.USER_EMAIL)
44  public final class RtUserEmailsITCase {
45  
46      /**
47       * RtUserEmails can fetch emails.
48       * @throws Exception If some problem inside
49       */
50      @Test
51      public void fetchesEmails() throws Exception {
52          MatcherAssert.assertThat(
53              RtUserEmailsITCase.userEmails().iterate(),
54              Matchers.not(Matchers.emptyIterableOf(String.class))
55          );
56      }
57  
58      /**
59       * RtUserEmails can add emails. Note that you must use a real email address
60       * (see http://mailinator.com/).
61       * @throws Exception If some problem inside
62       */
63      @Test
64      public void addsEmails() throws Exception {
65          final String email = "test@mailtothis.com";
66          final UserEmails emails = RtUserEmailsITCase.userEmails();
67          try {
68              MatcherAssert.assertThat(
69                  emails.add(Collections.singletonList(email)),
70                  Matchers.hasItem(email)
71              );
72              MatcherAssert.assertThat(emails.iterate(), Matchers.hasItem(email));
73          } finally {
74              emails.remove(Collections.singletonList(email));
75          }
76      }
77  
78      /**
79       * RtUserEmails can remove emails. Note that you must use a real email
80       * address (see http://mailinator.com/).
81       * @throws Exception If some problem inside
82       */
83      @Test
84      public void removesEmails() throws Exception {
85          final String email = "test1@mailtothis.com";
86          final UserEmails emails = RtUserEmailsITCase.userEmails();
87          emails.add(Collections.singletonList(email));
88          try {
89              MatcherAssert.assertThat(emails.iterate(), Matchers.hasItem(email));
90          } finally {
91              emails.remove(Collections.singletonList(email));
92          }
93          MatcherAssert.assertThat(
94              emails.iterate(), Matchers.not(Matchers.hasItem(email))
95          );
96      }
97  
98      /**
99       * Return UserEmails for tests.
100      * @return UserEmails
101      */
102     private static UserEmails userEmails() {
103         return new GithubIT().connect().users().self().emails();
104     }
105 
106 }