Coverage Report - com.jcabi.github.mock.MkGit
 
Classes in this File Line Coverage Branch Coverage Complexity
MkGit
56%
13/23
0%
0/22
2.714
MkGit$AjcClosure1
100%
1/1
N/A
2.714
MkGit$AjcClosure11
100%
1/1
N/A
2.714
MkGit$AjcClosure3
100%
1/1
N/A
2.714
MkGit$AjcClosure5
100%
1/1
N/A
2.714
MkGit$AjcClosure7
100%
1/1
N/A
2.714
MkGit$AjcClosure9
100%
1/1
N/A
2.714
 
 1  2
 /**
 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.Blobs;
 35  
 import com.jcabi.github.Commits;
 36  
 import com.jcabi.github.Coordinates;
 37  
 import com.jcabi.github.Git;
 38  
 import com.jcabi.github.References;
 39  
 import com.jcabi.github.Repo;
 40  
 import com.jcabi.github.Tags;
 41  
 import com.jcabi.github.Trees;
 42  
 import java.io.IOException;
 43  
 import javax.validation.constraints.NotNull;
 44  
 import lombok.EqualsAndHashCode;
 45  
 import lombok.ToString;
 46  
 import org.xembly.Directives;
 47  
 
 48  
 /**
 49  
  * Github Mock Git.
 50  
  *
 51  
  * @author Carlos Miranda (miranda.cma@gmail.com)
 52  
  * @version $Id$
 53  
  * @since 0.8
 54  
  */
 55  
 @Immutable
 56  
 @Loggable(Loggable.DEBUG)
 57  0
 @ToString
 58  0
 @EqualsAndHashCode(of = { "storage", "self", "coords" })
 59  
 final class MkGit implements Git {
 60  
 
 61  
     /**
 62  
      * Storage.
 63  
      */
 64  
     private final transient MkStorage storage;
 65  
 
 66  
     /**
 67  
      * Login of the user logged in.
 68  
      */
 69  
     private final transient String self;
 70  
 
 71  
     /**
 72  
      * Repo name.
 73  
      */
 74  
     private final transient Coordinates coords;
 75  
 
 76  
     /**
 77  
      * Public ctor.
 78  
      * @param stg Storage
 79  
      * @param login User to login
 80  
      * @param rep Repo
 81  
      * @throws IOException If there is any I/O problem
 82  
      */
 83  
     public MkGit(
 84  
         @NotNull(message = "stg can't be NULL") final MkStorage stg,
 85  
         @NotNull(message = "login can't be NULL") final String login,
 86  
         @NotNull(message = "rep can't be NULL") final Coordinates rep
 87  22
     ) throws IOException {
 88  22
         this.storage = stg;
 89  22
         this.self = login;
 90  22
         this.coords = rep;
 91  22
         this.storage.apply(
 92  
             new Directives().xpath(
 93  
                 String.format(
 94  
                     "/github/repos/repo[@coords='%s']",
 95  
                     this.coords
 96  
                 )
 97  
             ).addIf("git")
 98  
         );
 99  22
     }
 100  
 
 101  
     @Override
 102  
     @NotNull(message = "repo is never NULL")
 103  
     public Repo repo() {
 104  2
         return new MkRepo(this.storage, this.self, this.coords);
 105  
     }
 106  
 
 107  
     @Override
 108  
     @NotNull(message = "blobs is never NULL")
 109  
     public Blobs blobs() throws IOException {
 110  4
         return new MkBlobs(this.storage, this.self, this.coords);
 111  
     }
 112  
 
 113  
     @Override
 114  
     @NotNull(message = "commits is never NULL")
 115  
     public Commits commits() {
 116  
         try {
 117  2
             return new MkCommits(this.storage, this.self, this.coords);
 118  0
         } catch (final IOException ex) {
 119  0
             throw new IllegalStateException(ex);
 120  
         }
 121  
     }
 122  
 
 123  
     @Override
 124  
     @NotNull(message = "References is never NULL")
 125  
     public References references() {
 126  
         try {
 127  24
             return new MkReferences(this.storage, this.self, this.coords);
 128  0
         } catch (final IOException ex) {
 129  0
             throw new IllegalStateException(ex);
 130  
         }
 131  
     }
 132  
 
 133  
     @Override
 134  
     @NotNull(message = "Tags is never NULL")
 135  
     public Tags tags() {
 136  
         try {
 137  4
             return new MkTags(this.storage, this.self, this.coords);
 138  0
         } catch (final IOException ex) {
 139  0
             throw new IllegalStateException(ex);
 140  
         }
 141  
     }
 142  
 
 143  
     @Override
 144  
     @NotNull(message = "Trees is never NULL")
 145  
     public Trees trees() {
 146  
         try {
 147  8
             return new MkTrees(this.storage, this.self, this.coords);
 148  0
         } catch (final IOException ex) {
 149  0
             throw new IllegalStateException(ex);
 150  
         }
 151  
     }
 152  
 
 153  
 }