Coverage Report - com.jcabi.github.mock.MkCommit
 
Classes in this File Line Coverage Branch Coverage Complexity
MkCommit
62%
10/16
2%
1/36
1
MkCommit$AjcClosure1
100%
1/1
N/A
1
MkCommit$AjcClosure3
100%
1/1
N/A
1
MkCommit$AjcClosure5
0%
0/1
N/A
1
MkCommit$AjcClosure7
0%
0/1
N/A
1
 
 1  8
 /**
 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  
 
 31  
 package com.jcabi.github.mock;
 32  
 
 33  
 import com.jcabi.aspects.Immutable;
 34  
 import com.jcabi.aspects.Loggable;
 35  
 import com.jcabi.github.Commit;
 36  
 import com.jcabi.github.Coordinates;
 37  
 import com.jcabi.github.Repo;
 38  
 import java.io.IOException;
 39  
 import javax.json.JsonObject;
 40  
 import lombok.EqualsAndHashCode;
 41  
 
 42  
 /**
 43  
  * Mock of Github Commit.
 44  
  * @author Ed Hillmann (edhillmann@yahoo.com)
 45  
  * @version $Id: fcfa3793d4ca6dd67c38fa68460b7143bf6d3da1 $
 46  
  */
 47  0
 @Immutable
 48  
 @Loggable(Loggable.DEBUG)
 49  3
 @EqualsAndHashCode(of = { "storage", "self", "coords", "identifier" })
 50  
 public final class MkCommit implements Commit {
 51  
 
 52  
     /**
 53  
      * Storage.
 54  
      */
 55  
     private final transient MkStorage storage;
 56  
 
 57  
     /**
 58  
      * Login of the user logged in.
 59  
      */
 60  
     private final transient String self;
 61  
 
 62  
     /**
 63  
      * Repo name.
 64  
      */
 65  
     private final transient Coordinates coords;
 66  
 
 67  
     /**
 68  
      * The Commit's sha.
 69  
      */
 70  
     private final transient String identifier;
 71  
 
 72  
     /**
 73  
      * Public constructor.
 74  
      * @param strg The storage.
 75  
      * @param login The login name
 76  
      * @param crds Credential
 77  
      * @param commitsha Commit's sha.
 78  
      * @checkstyle ParameterNumber (5 lines)
 79  
      */
 80  
     public MkCommit(
 81  
         final MkStorage strg,
 82  
         final String login,
 83  
         final Coordinates crds,
 84  
         final String commitsha
 85  29
     ) {
 86  29
         this.storage = strg;
 87  29
         this.self = login;
 88  29
         this.coords = crds;
 89  29
         this.identifier = commitsha;
 90  29
     }
 91  
 
 92  
     @Override
 93  
     public Repo repo() {
 94  8
         return new MkRepo(this.storage, this.self, this.coords);
 95  
     }
 96  
 
 97  
     @Override
 98  
     public String sha() {
 99  16
         return this.identifier;
 100  
     }
 101  
 
 102  
     @Override
 103  
     public JsonObject json() throws IOException {
 104  0
         return new JsonNode(
 105  0
             this.storage.xml().nodes(this.xpath()).get(0)
 106  0
         ).json();
 107  
     }
 108  
 
 109  
     @Override
 110  
     public int compareTo(final Commit commit) {
 111  0
         return this.identifier.compareTo(commit.sha());
 112  
     }
 113  
 
 114  
     /**
 115  
      * XPath of this element in XML tree.
 116  
      *
 117  
      * @return XPath
 118  
      */
 119  
     private String xpath() {
 120  0
         return String.format(
 121  
             "/github/repos/repo[@coords = '%s']/git/commits/commit[sha = '%s']",
 122  
             this.coords, this.identifier
 123  
         );
 124  
     }
 125  
 }