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