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.mock;
31  
32  import com.jcabi.github.Milestone;
33  import com.jcabi.github.Milestones;
34  import com.jcabi.github.Repo;
35  import com.jcabi.immutable.ArrayMap;
36  import org.hamcrest.MatcherAssert;
37  import org.hamcrest.Matchers;
38  import org.junit.Test;
39  
40  /**
41   * Test class for MkMilestones.
42   * @author Mihai Andronache (amihaiemil@gmail.com)
43   * @version $Id: 23817291b7cc34af4522afc57e0fbd76de5fb77c $
44   * @checkstyle MultipleStringLiterals (500 lines)
45   */
46  public final class MkMilestonesTest {
47  
48      /**
49       * This tests that MkMilestones can return its owner repo.
50       * @throws Exception - if something goes wrong.
51       */
52      @Test
53      public void returnsRepo() throws Exception {
54          final Repo repo = new MkGithub().randomRepo();
55          final Repo owner = repo.milestones().repo();
56          MatcherAssert.assertThat(repo, Matchers.is(owner));
57      }
58  
59      /**
60       * This tests that MkMilestones can create a MkMilestone.
61       * @throws Exception - if something goes wrong.
62       */
63      @Test
64      public void createsMilestone() throws Exception {
65          final Milestones milestones = new MkGithub().randomRepo()
66              .milestones();
67          final Milestone milestone = milestones.create("test milestone");
68          MatcherAssert.assertThat(milestone, Matchers.notNullValue());
69          MatcherAssert.assertThat(
70              milestones.create("another milestone"),
71              Matchers.notNullValue()
72          );
73      }
74  
75      /**
76       * This tests that MkMilestones can return a certain MkMilestone, by number.
77       * @throws Exception - if something goes wrong.
78       */
79      @Test
80      public void getsMilestone() throws Exception {
81          final Milestones milestones = new MkGithub().randomRepo()
82              .milestones();
83          final Milestone created = milestones.create("test");
84          MatcherAssert.assertThat(
85              milestones.get(created.number()),
86              Matchers.notNullValue()
87          );
88      }
89      /**
90       * This tests that MkMilestones can remove a certain MkMilestone, by number.
91       * @throws Exception - if something goes wrong.
92       */
93      @Test
94      public void removesMilestone() throws Exception {
95          final Milestones milestones = new MkGithub().randomRepo()
96              .milestones();
97          final Milestone created = milestones.create("testTitle");
98          MatcherAssert.assertThat(
99              milestones.iterate(new ArrayMap<>()),
100             Matchers.<Milestone>iterableWithSize(1)
101         );
102         milestones.remove(created.number());
103         MatcherAssert.assertThat(
104             milestones.iterate(new ArrayMap<>()),
105             Matchers.<Milestone>iterableWithSize(0)
106         );
107     }
108     /**
109      * This tests that the iterate(Map<String, String> params)
110      * method in MkMilestones works fine.
111      * @throws Exception - if something goes wrong.
112      */
113     @Test
114     public void iteratesMilestones() throws Exception {
115         final Milestones milestones = new MkGithub().randomRepo()
116             .milestones();
117         milestones.create("testMilestone");
118         MatcherAssert.assertThat(
119             milestones.iterate(new ArrayMap<>()),
120             Matchers.<Milestone>iterableWithSize(1)
121         );
122     }
123 }