Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MkCommits |
|
| 1.0;1 | ||||
MkCommits$AjcClosure1 |
|
| 1.0;1 | ||||
MkCommits$AjcClosure3 |
|
| 1.0;1 | ||||
MkCommits$AjcClosure5 |
|
| 1.0;1 | ||||
MkCommits$AjcClosure7 |
|
| 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.Commit; | |
36 | import com.jcabi.github.Commits; | |
37 | import com.jcabi.github.Coordinates; | |
38 | import com.jcabi.github.Repo; | |
39 | import com.jcabi.github.Statuses; | |
40 | import java.io.IOException; | |
41 | import javax.json.JsonObject; | |
42 | import lombok.EqualsAndHashCode; | |
43 | import org.xembly.Directives; | |
44 | ||
45 | /** | |
46 | * Mock of Github Commits. | |
47 | * @author Ed Hillmann (edhillmann@yahoo.com) | |
48 | * @version $Id: ff1957a6a532d4ba200ded851adebf8744a71953 $ | |
49 | */ | |
50 | @Immutable | |
51 | @Loggable(Loggable.DEBUG) | |
52 | 0 | @EqualsAndHashCode(of = { "storage", "self", "coords" }) |
53 | public final class MkCommits implements Commits { | |
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's name. | |
67 | */ | |
68 | private final transient Coordinates coords; | |
69 | ||
70 | /** | |
71 | * Public constructor. | |
72 | * @param stg The storage. | |
73 | * @param login The login name. | |
74 | * @param rep Repo's coordinates. | |
75 | * @throws IOException If something goes wrong. | |
76 | */ | |
77 | MkCommits( | |
78 | final MkStorage stg, | |
79 | final String login, | |
80 | final Coordinates rep | |
81 | 23 | ) throws IOException { |
82 | 23 | this.storage = stg; |
83 | 23 | this.self = login; |
84 | 23 | this.coords = rep; |
85 | 46 | this.storage.apply( |
86 | 23 | new Directives().xpath( |
87 | 23 | String.format( |
88 | "/github/repos/repo[@coords='%s']/git", | |
89 | this.coords | |
90 | ) | |
91 | 23 | ).addIf("commits") |
92 | ); | |
93 | 23 | } |
94 | @Override | |
95 | public Repo repo() { | |
96 | 0 | return new MkRepo(this.storage, this.self, this.coords); |
97 | } | |
98 | ||
99 | @Override | |
100 | public Commit create( | |
101 | final JsonObject params | |
102 | ) { | |
103 | 2 | return this.get(params.getString("sha")); |
104 | } | |
105 | ||
106 | @Override | |
107 | public Commit get( | |
108 | final String sha | |
109 | ) { | |
110 | 46 | return new MkCommit(this.storage, this.self, this.coords, sha); |
111 | } | |
112 | ||
113 | @Override | |
114 | public Statuses statuses( | |
115 | final String sha | |
116 | ) { | |
117 | 0 | return new MkStatuses(this.get(sha)); |
118 | } | |
119 | } |