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