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