Coverage Report - com.jcabi.github.mock.MkRepo
 
Classes in this File Line Coverage Branch Coverage Complexity
MkRepo
55%
43/78
32%
9/28
2.92
MkRepo$AjcClosure1
100%
1/1
N/A
2.92
MkRepo$AjcClosure11
100%
1/1
N/A
2.92
MkRepo$AjcClosure13
100%
1/1
N/A
2.92
MkRepo$AjcClosure15
100%
1/1
N/A
2.92
MkRepo$AjcClosure17
100%
1/1
N/A
2.92
MkRepo$AjcClosure19
100%
1/1
N/A
2.92
MkRepo$AjcClosure21
100%
1/1
N/A
2.92
MkRepo$AjcClosure23
100%
1/1
N/A
2.92
MkRepo$AjcClosure25
100%
1/1
N/A
2.92
MkRepo$AjcClosure27
100%
1/1
N/A
2.92
MkRepo$AjcClosure29
100%
1/1
N/A
2.92
MkRepo$AjcClosure3
100%
1/1
N/A
2.92
MkRepo$AjcClosure31
100%
1/1
N/A
2.92
MkRepo$AjcClosure33
100%
1/1
N/A
2.92
MkRepo$AjcClosure35
100%
1/1
N/A
2.92
MkRepo$AjcClosure37
100%
1/1
N/A
2.92
MkRepo$AjcClosure39
100%
1/1
N/A
2.92
MkRepo$AjcClosure41
100%
1/1
N/A
2.92
MkRepo$AjcClosure43
100%
1/1
N/A
2.92
MkRepo$AjcClosure45
0%
0/1
N/A
2.92
MkRepo$AjcClosure5
100%
1/1
N/A
2.92
MkRepo$AjcClosure7
100%
1/1
N/A
2.92
MkRepo$AjcClosure9
100%
1/1
N/A
2.92
 
 1  88
 /**
 2  
  * Copyright (c) 2013-2017, 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.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import com.jcabi.github.Assignees;
 35  
 import com.jcabi.github.Branches;
 36  
 import com.jcabi.github.Collaborators;
 37  
 import com.jcabi.github.Contents;
 38  
 import com.jcabi.github.Coordinates;
 39  
 import com.jcabi.github.DeployKeys;
 40  
 import com.jcabi.github.Forks;
 41  
 import com.jcabi.github.Git;
 42  
 import com.jcabi.github.Github;
 43  
 import com.jcabi.github.Hooks;
 44  
 import com.jcabi.github.IssueEvents;
 45  
 import com.jcabi.github.Issues;
 46  
 import com.jcabi.github.Labels;
 47  
 import com.jcabi.github.Language;
 48  
 import com.jcabi.github.Milestones;
 49  
 import com.jcabi.github.Notifications;
 50  
 import com.jcabi.github.Pulls;
 51  
 import com.jcabi.github.Releases;
 52  
 import com.jcabi.github.Repo;
 53  
 import com.jcabi.github.RepoCommits;
 54  
 import com.jcabi.github.RtLanguage;
 55  
 import com.jcabi.github.Stars;
 56  
 import java.io.IOException;
 57  
 import java.util.ArrayList;
 58  
 import java.util.List;
 59  
 import javax.json.JsonObject;
 60  
 import lombok.EqualsAndHashCode;
 61  
 import lombok.ToString;
 62  
 
 63  
 /**
 64  
  * Mock Github repo.
 65  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 66  
  * @version $Id: 21e6a669a59908f19a82ef061f739b897d02ef5d $
 67  
  * @since 0.5
 68  
  * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
 69  
  * @checkstyle ClassFanOutComplexity (500 lines)
 70  
  * @todo #1061 Fix code to avoid CouplingBetweenObjects
 71  
  */
 72  0
 @Immutable
 73  
 @Loggable(Loggable.DEBUG)
 74  0
 @ToString
 75  10
 @EqualsAndHashCode(of = {"storage", "self", "coords" })
 76  
 @SuppressWarnings
 77  
     (
 78  
         {
 79  
             "PMD.TooManyMethods",
 80  
             "PMD.ExcessiveImports",
 81  
             "PMD.CouplingBetweenObjects"
 82  
         }
 83  
     )
 84  
 final class MkRepo implements Repo {
 85  
 
 86  
     /**
 87  
      * Storage.
 88  
      */
 89  
     private final transient MkStorage storage;
 90  
 
 91  
     /**
 92  
      * Login of the user logged in.
 93  
      */
 94  
     private final transient String self;
 95  
 
 96  
     /**
 97  
      * Repo coordinates.
 98  
      */
 99  
     private final transient Coordinates coords;
 100  
 
 101  
     /**
 102  
      * Public ctor.
 103  
      * @param stg Storage
 104  
      * @param login User to login
 105  
      * @param repo Repo name
 106  
      */
 107  
     MkRepo(
 108  
         final MkStorage stg,
 109  
         final String login,
 110  
         final Coordinates repo
 111  521
     ) {
 112  521
         this.storage = stg;
 113  521
         this.self = login;
 114  521
         this.coords = repo;
 115  521
     }
 116  
 
 117  
     @Override
 118  
     public Github github() {
 119  51
         return new MkGithub(this.storage, this.self);
 120  
     }
 121  
 
 122  
     @Override
 123  
     public Coordinates coordinates() {
 124  690
         return this.coords;
 125  
     }
 126  
 
 127  
     @Override
 128  
     public Issues issues() {
 129  
         try {
 130  336
             return new MkIssues(this.storage, this.self, this.coords);
 131  0
         } catch (final IOException ex) {
 132  0
             throw new IllegalStateException(ex);
 133  
         }
 134  
     }
 135  
 
 136  
     @Override
 137  
     public Milestones milestones() {
 138  
         try {
 139  12
             return new MkMilestones(this.storage, this.self, this.coords);
 140  0
         } catch (final IOException ex) {
 141  0
             throw new IllegalStateException(ex);
 142  
         }
 143  
     }
 144  
 
 145  
     @Override
 146  
     public Pulls pulls() {
 147  
         try {
 148  36
             return new MkPulls(this.storage, this.self, this.coords);
 149  0
         } catch (final IOException ex) {
 150  0
             throw new IllegalStateException(ex);
 151  
         }
 152  
     }
 153  
 
 154  
     @Override
 155  
     public Hooks hooks() {
 156  
         try {
 157  9
             return new MkHooks(this.storage, this.self, this.coords);
 158  0
         } catch (final IOException ex) {
 159  0
             throw new IllegalStateException(ex);
 160  
         }
 161  
     }
 162  
 
 163  
     @Override
 164  
     public IssueEvents issueEvents() {
 165  
         try {
 166  14
             return new MkIssueEvents(this.storage, this.self, this.coords);
 167  0
         } catch (final IOException ex) {
 168  0
             throw new IllegalStateException(ex);
 169  
         }
 170  
     }
 171  
 
 172  
     @Override
 173  
     public Labels labels() {
 174  
         try {
 175  30
             return new MkLabels(this.storage, this.self, this.coords);
 176  0
         } catch (final IOException ex) {
 177  0
             throw new IllegalStateException(ex);
 178  
         }
 179  
     }
 180  
 
 181  
     @Override
 182  
     public Assignees assignees() {
 183  
         try {
 184  6
             return new MkAssignees(this.storage, this.self, this.coords);
 185  0
         } catch (final IOException ex) {
 186  0
             throw new IllegalStateException(ex);
 187  
         }
 188  
     }
 189  
 
 190  
     @Override
 191  
     public Releases releases() {
 192  
         try {
 193  66
             return new MkReleases(this.storage, this.self, this.coords);
 194  0
         } catch (final IOException ex) {
 195  0
             throw new IllegalStateException(ex);
 196  
         }
 197  
     }
 198  
 
 199  
     @Override
 200  
     public Forks forks() {
 201  
         try {
 202  6
             return new MkForks(this.storage, this.self, this.coords);
 203  0
         } catch (final IOException ex) {
 204  0
             throw new IllegalStateException(ex);
 205  
         }
 206  
     }
 207  
 
 208  
     @Override
 209  
     public Collaborators collaborators() {
 210  
         try {
 211  6
             return new MkCollaborators(this.storage, this.self, this.coords);
 212  0
         } catch (final IOException ex) {
 213  0
             throw new IllegalStateException(ex);
 214  
         }
 215  
     }
 216  
 
 217  
     @Override
 218  
     public DeployKeys keys() {
 219  
         try {
 220  10
             return new MkDeployKeys(this.storage, this.self, this.coords);
 221  0
         } catch (final IOException ex) {
 222  0
             throw new IllegalStateException(ex);
 223  
         }
 224  
     }
 225  
 
 226  
     @Override
 227  
     public Contents contents() {
 228  
         try {
 229  44
             return new MkContents(this.storage, this.self, this.coords);
 230  0
         } catch (final IOException ex) {
 231  0
             throw new IllegalStateException(ex);
 232  
         }
 233  
     }
 234  
 
 235  
     @Override
 236  
     public void patch(
 237  
         final JsonObject json
 238  
     ) throws IOException {
 239  484
         new JsonPatch(this.storage).patch(this.xpath(), json);
 240  242
     }
 241  
 
 242  
     @Override
 243  
     public RepoCommits commits() {
 244  
         try {
 245  6
             return new MkRepoCommits(
 246  2
                 this.storage, this.self, this.coordinates()
 247  
             );
 248  0
         } catch (final IOException ex) {
 249  0
             throw new IllegalStateException(ex);
 250  
         }
 251  
     }
 252  
 
 253  
     @Override
 254  
     public Branches branches() {
 255  
         try {
 256  45
             return new MkBranches(
 257  15
                 this.storage, this.self, this.coordinates()
 258  
             );
 259  0
         } catch (final IOException ex) {
 260  0
             throw new IllegalStateException(ex);
 261  
         }
 262  
     }
 263  
 
 264  
     @Override
 265  
     public Git git() {
 266  
         try {
 267  88
             return new MkGit(this.storage, this.self, this.coords);
 268  0
         } catch (final IOException ex) {
 269  0
             throw new IllegalStateException(ex);
 270  
         }
 271  
     }
 272  
 
 273  
     @Override
 274  
     public Stars stars() {
 275  
         try {
 276  6
             return new MkStars(this.storage, this.self, this.coords);
 277  0
         } catch (final IOException ex) {
 278  0
             throw new IllegalStateException(ex);
 279  
         }
 280  
     }
 281  
 
 282  
     @Override
 283  
     public Notifications notifications() {
 284  3
         return new MkNotifications(
 285  
             this.storage,
 286  1
             this.xpath().concat("/notifications/notification")
 287  
         );
 288  
     }
 289  
 
 290  
     @Override
 291  
     public Iterable<Language> languages() {
 292  2
         final List<Language> languages = new ArrayList<Language>(0);
 293  1
         final int java = 999;
 294  1
         languages.add(new RtLanguage("Java", java));
 295  1
         final int php = 888;
 296  1
         languages.add(new RtLanguage("PHP", php));
 297  1
         final int ruby = 777;
 298  1
         languages.add(new RtLanguage("Ruby", ruby));
 299  1
         return languages;
 300  
     }
 301  
 
 302  
     @Override
 303  
     public JsonObject json() throws IOException {
 304  15
         return new JsonNode(
 305  5
             this.storage.xml().nodes(this.xpath()).get(0)
 306  5
         ).json();
 307  
     }
 308  
 
 309  
     @Override
 310  
     public int compareTo(final Repo repo) {
 311  0
         return this.coords.compareTo(repo.coordinates());
 312  
     }
 313  
 
 314  
     /**
 315  
      * XPath of this element in XML tree.
 316  
      * @return XPath
 317  
      */
 318  
     private String xpath() {
 319  248
         return String.format(
 320  
             "/github/repos/repo[@coords='%s']",
 321  
             this.coords
 322  
         );
 323  
     }
 324  
 
 325  
 }