Coverage Report - com.jcabi.github.mock.MkTag
 
Classes in this File Line Coverage Branch Coverage Complexity
MkTag
80%
12/15
0%
0/36
1
MkTag$AjcClosure1
100%
1/1
N/A
1
MkTag$AjcClosure3
0%
0/1
N/A
1
MkTag$AjcClosure5
0%
0/1
N/A
1
 
 1  2
 /**
 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.Coordinates;
 36  
 import com.jcabi.github.Repo;
 37  
 import com.jcabi.github.Tag;
 38  
 import java.io.IOException;
 39  
 import javax.json.JsonObject;
 40  
 import lombok.EqualsAndHashCode;
 41  
 
 42  
 /**
 43  
  * Mock of Github Tag.
 44  
  * @author Mihai Andronache (amihaiemil@gmail.com)
 45  
  * @version $Id: e7ea82e76e78c0d5c283d6440cb719f5ebc7d52d $
 46  
  */
 47  
 @Immutable
 48  
 @Loggable(Loggable.DEBUG)
 49  0
 @EqualsAndHashCode(of = { "storage", "self", "coords", "sha" })
 50  
 final class MkTag implements Tag {
 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 Tag's sha.
 69  
      */
 70  
     private final transient String sha;
 71  
 
 72  
     /**
 73  
      * Public constructor.
 74  
      * @param strg The storage.
 75  
      * @param login The login name
 76  
      * @param crds Credential
 77  
      * @param identifier Tag's sha.
 78  
      * @checkstyle ParameterNumber (5 lines)
 79  
      */
 80  
     MkTag(
 81  
         final MkStorage strg,
 82  
         final String login,
 83  
         final Coordinates crds,
 84  
         final String identifier
 85  2
     ) {
 86  2
         this.storage = strg;
 87  2
         this.self = login;
 88  2
         this.coords = crds;
 89  2
         this.sha = new StringBuilder().append('"').append(identifier)
 90  2
             .append('"').toString();
 91  2
     }
 92  
 
 93  
     @Override
 94  
     public JsonObject json() throws IOException {
 95  3
         return new JsonNode(
 96  1
             this.storage.xml().nodes(this.xpath()).get(0)
 97  1
         ).json();
 98  
     }
 99  
 
 100  
     @Override
 101  
     public Repo repo() {
 102  0
         return new MkRepo(this.storage, this.self, this.coords);
 103  
     }
 104  
 
 105  
     @Override
 106  
     public String key() {
 107  0
         return this.sha;
 108  
     }
 109  
 
 110  
     /**
 111  
      * XPath of this element in XML tree.
 112  
      *
 113  
      * @return XPath
 114  
      */
 115  
     private String xpath() {
 116  1
         return String.format(
 117  
             "/github/repos/repo[@coords = '%s']/git/tags/tag[sha = '%s']",
 118  
             this.coords, this.sha
 119  
         );
 120  
     }
 121  
 
 122  
 }