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