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.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: a61dd00fda2ff5226e10a194d16fa991ad8f6eb8 $
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       */
57      @Test
58      public void iterateEmpty() {
59          MatcherAssert.assertThat(
60              new RtNotifications(
61                  new FakeRequest()
62                      .withBody("[]")
63              ).iterate(),
64              Matchers.emptyIterable()
65          );
66      }
67  
68      /**
69       * Method 'iterate()' will iterate over notifications sent by the service.
70       */
71      @Test
72      public void iterateNotifications() {
73          MatcherAssert.assertThat(
74              new RtNotifications(
75                  new FakeRequest().withBody(
76                      // @checkstyle StringLiteralsConcatenationCheck (50 lines)
77                      // @checkstyle LineLength (50 lines)
78                      "[\n"
79                      + "  {\n"
80                      + "    \"id\": \"1\",\n"
81                      + "    \"repository\": {\n"
82                      + "      \"id\": 1296269,\n"
83                      + "      \"owner\": {\n"
84                      + "        \"login\": \"octocat\",\n"
85                      + "        \"id\": 1,\n"
86                      + "        \"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\",\n"
87                      + "        \"gravatar_id\": \"\",\n"
88                      + "        \"url\": \"https://api.github.com/users/octocat\",\n"
89                      + "        \"html_url\": \"https://github.com/octocat\",\n"
90                      + "        \"followers_url\": \"https://api.github.com/users/octocat/followers\",\n"
91                      + "        \"following_url\": \"https://api.github.com/users/octocat/following{/other_user}\",\n"
92                      + "        \"gists_url\": \"https://api.github.com/users/octocat/gists{/gist_id}\",\n"
93                      + "        \"starred_url\": \"https://api.github.com/users/octocat/starred{/owner}{/repo}\",\n"
94                      + "        \"subscriptions_url\": \"https://api.github.com/users/octocat/subscriptions\",\n"
95                      + "        \"organizations_url\": \"https://api.github.com/users/octocat/orgs\",\n"
96                      + "        \"repos_url\": \"https://api.github.com/users/octocat/repos\",\n"
97                      + "        \"events_url\": \"https://api.github.com/users/octocat/events{/privacy}\",\n"
98                      + "        \"received_events_url\": \"https://api.github.com/users/octocat/received_events\",\n"
99                      + "        \"type\": \"User\",\n"
100                     + "        \"site_admin\": false\n"
101                     + "      },\n"
102                     + "      \"name\": \"Hello-World\",\n"
103                     + "      \"full_name\": \"octocat/Hello-World\",\n"
104                     + "      \"description\": \"This your first repo!\",\n"
105                     + "      \"private\": false,\n"
106                     + "      \"fork\": false,\n"
107                     + "      \"url\": \"https://api.github.com/repos/octocat/Hello-World\",\n"
108                     + "      \"html_url\": \"https://github.com/octocat/Hello-World\"\n"
109                     + "    },\n"
110                     + "    \"subject\": {\n"
111                     + "      \"title\": \"Greetings\",\n"
112                     + "      \"url\": \"https://api.github.com/repos/octokit/octokit.rb/issues/123\",\n"
113                     + "      \"latest_comment_url\": \"https://api.github.com/repos/octokit/octokit.rb/issues/comments/123\",\n"
114                     + "      \"type\": \"Issue\"\n"
115                     + "    },\n"
116                     + "    \"reason\": \"subscribed\",\n"
117                     + "    \"unread\": true,\n"
118                     + "    \"updated_at\": \"2014-11-07T22:01:45Z\",\n"
119                     + "    \"last_read_at\": \"2014-11-07T22:01:45Z\",\n"
120                     + "    \"url\": \"https://api.github.com/notifications/threads/1\"\n"
121                     + "  }\n"
122                     + "]"
123                 )
124             ).iterate(),
125             Matchers.not(Matchers.emptyIterable())
126         );
127     }
128 
129     /**
130      * RtNotifications can mark Notification as read.
131      */
132     @Test
133     @Ignore
134     public void markNotificationAsRead() {
135         // Not implemented
136     }
137 }