View Javadoc
1   /**
2    * Copyright (c) 2013-2022, 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.http.request.FakeRequest;
33  import org.hamcrest.MatcherAssert;
34  import org.hamcrest.Matchers;
35  import org.junit.Ignore;
36  import org.junit.Test;
37  
38  /**
39   * Test case for {@link RtNotifications}.
40   *
41   * @author Paul Polishchuk (ppol@ua.fm)
42   * @version $Id: 0a8a8c2aa84d16dff24067443a81dfaf7c35b5a5 $
43   * @todo #920 Create a test fetchSingleNotification and implement
44   *  get() operation in RtNotifications.
45   * @todo #920 Create a test fetchNonEmptyListOfNotifications and implement
46   *  iterate() operation in RtNotifications.
47   * @todo #920 Create a test markNotificationAsRead and implement
48   *  mark() operation in RtNotifications.
49   * @checkstyle MultipleStringLiteralsCheck (500 lines)
50   */
51  public final class RtNotificationsTest {
52  
53      /**
54       * Method 'iterate()' returns empty iterable if the service responds with
55       * no notifications.
56       * @throws Exception if some problem inside
57       */
58      @Test
59      public void iterateEmpty() throws Exception {
60          MatcherAssert.assertThat(
61              new RtNotifications(
62                  new FakeRequest()
63                      .withBody("[]")
64              ).iterate(),
65              Matchers.emptyIterable()
66          );
67      }
68  
69      /**
70       * Method 'iterate()' will iterate over notifications sent by the service.
71       * @throws Exception If some problem inside
72       */
73      @Test
74      public void iterateNotifications() throws Exception {
75          MatcherAssert.assertThat(
76              new RtNotifications(
77                  new FakeRequest().withBody(
78                      // @checkstyle StringLiteralsConcatenationCheck (50 lines)
79                      // @checkstyle LineLength (50 lines)
80                      "[\n"
81                      + "  {\n"
82                      + "    \"id\": \"1\",\n"
83                      + "    \"repository\": {\n"
84                      + "      \"id\": 1296269,\n"
85                      + "      \"owner\": {\n"
86                      + "        \"login\": \"octocat\",\n"
87                      + "        \"id\": 1,\n"
88                      + "        \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n"
89                      + "        \"gravatar_id\": \"\",\n"
90                      + "        \"url\": \"https://api.github.com/users/octocat\",\n"
91                      + "        \"html_url\": \"https://github.com/octocat\",\n"
92                      + "        \"followers_url\": \"https://api.github.com/users/octocat/followers\",\n"
93                      + "        \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n"
94                      + "        \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n"
95                      + "        \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n"
96                      + "        \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n"
97                      + "        \"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n"
98                      + "        \"repos_url\": \"https://api.github.com/users/octocat/repos\",\n"
99                      + "        \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n"
100                     + "        \"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n"
101                     + "        \"type\": \"User\",\n"
102                     + "        \"site_admin\": false\n"
103                     + "      },\n"
104                     + "      \"name\": \"Hello-World\",\n"
105                     + "      \"full_name\": \"octocat/Hello-World\",\n"
106                     + "      \"description\": \"This your first repo!\",\n"
107                     + "      \"private\": false,\n"
108                     + "      \"fork\": false,\n"
109                     + "      \"url\": \"https://api.github.com/repos/octocat/Hello-World\",\n"
110                     + "      \"html_url\": \"https://github.com/octocat/Hello-World\"\n"
111                     + "    },\n"
112                     + "    \"subject\": {\n"
113                     + "      \"title\": \"Greetings\",\n"
114                     + "      \"url\": \"https://api.github.com/repos/octokit/octokit.rb/issues/123\",\n"
115                     + "      \"latest_comment_url\": \"https://api.github.com/repos/octokit/octokit.rb/issues/comments/123\",\n"
116                     + "      \"type\": \"Issue\"\n"
117                     + "    },\n"
118                     + "    \"reason\": \"subscribed\",\n"
119                     + "    \"unread\": true,\n"
120                     + "    \"updated_at\": \"2014-11-07T22:01:45Z\",\n"
121                     + "    \"last_read_at\": \"2014-11-07T22:01:45Z\",\n"
122                     + "    \"url\": \"https://api.github.com/notifications/threads/1\"\n"
123                     + "  }\n"
124                     + "]"
125                 )
126             ).iterate(),
127             Matchers.not(Matchers.emptyIterable())
128         );
129     }
130 
131     /**
132      * RtNotifications can mark Notification as read.
133      * @throws Exception If some problem inside
134      */
135     @Test
136     @Ignore
137     public void markNotificationAsRead() throws Exception  {
138         // Not implemented
139     }
140 }