Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MkLabel |
|
| 1.0;1 | ||||
MkLabel$AjcClosure1 |
|
| 1.0;1 | ||||
MkLabel$AjcClosure3 |
|
| 1.0;1 | ||||
MkLabel$AjcClosure5 |
|
| 1.0;1 | ||||
MkLabel$AjcClosure7 |
|
| 1.0;1 | ||||
MkLabel$AjcClosure9 |
|
| 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 | package com.jcabi.github.mock; | |
31 | ||
32 | import com.jcabi.aspects.Immutable; | |
33 | import com.jcabi.aspects.Loggable; | |
34 | import com.jcabi.github.Coordinates; | |
35 | import com.jcabi.github.Label; | |
36 | import com.jcabi.github.Repo; | |
37 | import java.io.IOException; | |
38 | import javax.json.JsonObject; | |
39 | import lombok.EqualsAndHashCode; | |
40 | import lombok.ToString; | |
41 | ||
42 | /** | |
43 | * Mock Github label. | |
44 | * | |
45 | * @author Yegor Bugayenko (yegor@tpc2.com) | |
46 | * @version $Id: 31946a0a24c120a08def8a49cabfda2b2cd93547 $ | |
47 | * @since 0.6 | |
48 | */ | |
49 | 0 | @Immutable |
50 | @Loggable(Loggable.DEBUG) | |
51 | 0 | @ToString |
52 | 0 | @EqualsAndHashCode(of = { "storage", "self", "owner", "label" }) |
53 | final class MkLabel implements Label { | |
54 | ||
55 | /** | |
56 | * Storage. | |
57 | */ | |
58 | private final transient MkStorage storage; | |
59 | ||
60 | /** | |
61 | * Login of the user logged in. | |
62 | */ | |
63 | private final transient String self; | |
64 | ||
65 | /** | |
66 | * Repo name. | |
67 | */ | |
68 | private final transient Coordinates owner; | |
69 | ||
70 | /** | |
71 | * Name of the label. | |
72 | */ | |
73 | private final transient String label; | |
74 | ||
75 | /** | |
76 | * Public ctor. | |
77 | * @param stg Storage | |
78 | * @param login User to login | |
79 | * @param rep Repo | |
80 | * @param name Label name | |
81 | * @checkstyle ParameterNumber (5 lines) | |
82 | */ | |
83 | MkLabel(final MkStorage stg, | |
84 | final String login, | |
85 | final Coordinates rep, | |
86 | final String name | |
87 | 18 | ) { |
88 | 18 | this.storage = stg; |
89 | 18 | this.self = login; |
90 | 18 | this.owner = rep; |
91 | 18 | this.label = name; |
92 | 18 | } |
93 | ||
94 | @Override | |
95 | public Repo repo() { | |
96 | 0 | return new MkRepo(this.storage, this.self, this.owner); |
97 | } | |
98 | ||
99 | @Override | |
100 | public String name() { | |
101 | 12 | return this.label; |
102 | } | |
103 | ||
104 | @Override | |
105 | public void patch(final JsonObject json | |
106 | ) throws IOException { | |
107 | 0 | new JsonPatch(this.storage).patch(this.xpath(), json); |
108 | 0 | } |
109 | ||
110 | @Override | |
111 | public JsonObject json() throws IOException { | |
112 | 6 | return new JsonNode( |
113 | 2 | this.storage.xml().nodes(this.xpath()).get(0) |
114 | 2 | ).json(); |
115 | } | |
116 | ||
117 | @Override | |
118 | public int compareTo(final Label lbl | |
119 | ) { | |
120 | 0 | return this.label.compareTo(lbl.name()); |
121 | } | |
122 | ||
123 | /** | |
124 | * XPath of this element in XML tree. | |
125 | * @return XPath | |
126 | */ | |
127 | private String xpath() { | |
128 | 2 | return String.format( |
129 | "/github/repos/repo[@coords='%s']/labels/label[name='%s']", | |
130 | this.owner, this.label | |
131 | ); | |
132 | } | |
133 | ||
134 | } |