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