Coverage Report - com.jcabi.github.mock.MkRepoCommit
 
Classes in this File Line Coverage Branch Coverage Complexity
MkRepoCommit
76%
10/13
0%
0/16
1
MkRepoCommit$AjcClosure1
100%
1/1
N/A
1
MkRepoCommit$AjcClosure3
100%
1/1
N/A
1
MkRepoCommit$AjcClosure5
100%
1/1
N/A
1
MkRepoCommit$AjcClosure7
100%
1/1
N/A
1
 
 1  32
 /**
 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.Repo;
 35  
 import com.jcabi.github.RepoCommit;
 36  
 import java.io.IOException;
 37  
 import javax.json.JsonObject;
 38  
 import javax.validation.constraints.NotNull;
 39  
 import lombok.EqualsAndHashCode;
 40  
 import lombok.ToString;
 41  
 import org.apache.commons.lang3.builder.CompareToBuilder;
 42  
 
 43  
 /**
 44  
  * Mock Github commit.
 45  
  * @author Carlos Crespo (carlos.a.crespo@gmail.com)
 46  
  * @version $Id$
 47  
  */
 48  0
 @Immutable
 49  
 @Loggable(Loggable.DEBUG)
 50  0
 @ToString
 51  0
 @EqualsAndHashCode(of = { "repository", "hash" })
 52  
 final class MkRepoCommit implements RepoCommit {
 53  
 
 54  
     /**
 55  
      * Commit SHA.
 56  
      */
 57  
     private final transient String hash;
 58  
 
 59  
     /**
 60  
      * The storage.
 61  
      */
 62  
     private final transient MkStorage storage;
 63  
     /**
 64  
      * The repository.
 65  
      */
 66  
     private final transient Repo repository;
 67  
 
 68  
     /**
 69  
      * Public ctor.
 70  
      * @param stg The storage
 71  
      * @param repo The repository
 72  
      * @param sha Commit SHA
 73  
      */
 74  
     MkRepoCommit(
 75  
         @NotNull(message = "storage must not be NULL")
 76  
         final MkStorage stg,
 77  
         @NotNull(message = "repo must not be null")
 78  
         final Repo repo,
 79  
         @NotNull(message = "sha must not be NULL")
 80  34
         final String sha) {
 81  34
         this.storage = stg;
 82  34
         this.repository = repo;
 83  34
         this.hash = sha;
 84  34
     }
 85  
 
 86  
     @Override
 87  
     public int compareTo(
 88  
         @NotNull(message = "other can't be NULL") final RepoCommit other
 89  
     ) {
 90  12
         return new CompareToBuilder().append(
 91  
             this.repo().coordinates(),
 92  
             other.repo().coordinates()
 93  
         ).append(this.sha(), other.sha()).build();
 94  
     }
 95  
 
 96  
     @Override
 97  
     @NotNull(message = "JSON is never NULL")
 98  
     public JsonObject json() throws IOException {
 99  6
         return new JsonNode(
 100  
             this.storage.xml().nodes(
 101  
                 String.format(
 102  
                     "/github/repos/repo[@coords='%s']/commits/commit[sha='%s']",
 103  
                         this.repo().coordinates(), this.hash
 104  
                 )
 105  
             ).get(0)
 106  
         ).json();
 107  
     }
 108  
 
 109  
     @Override
 110  
     @NotNull(message = "repository is never NULL")
 111  
     public Repo repo() {
 112  32
         return this.repository;
 113  
     }
 114  
 
 115  
     @Override
 116  
     @NotNull(message = "sha should no be NULL")
 117  
     public String sha() {
 118  28
         return this.hash;
 119  
     }
 120  
 
 121  
 }