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