| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MkCommitsComparison |
|
| 1.0;1 | ||||
| MkCommitsComparison$AjcClosure1 |
|
| 1.0;1 | ||||
| MkCommitsComparison$AjcClosure3 |
|
| 1.0;1 | ||||
| MkCommitsComparison$AjcClosure5 |
|
| 1.0;1 |
| 1 | 4 | /** |
| 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.google.common.collect.ImmutableList; | |
| 33 | import com.jcabi.aspects.Immutable; | |
| 34 | import com.jcabi.aspects.Loggable; | |
| 35 | import com.jcabi.github.CommitsComparison; | |
| 36 | import com.jcabi.github.Coordinates; | |
| 37 | import com.jcabi.github.FileChange; | |
| 38 | import com.jcabi.github.Repo; | |
| 39 | import java.io.IOException; | |
| 40 | import javax.json.Json; | |
| 41 | import javax.json.JsonObject; | |
| 42 | import lombok.ToString; | |
| 43 | ||
| 44 | /** | |
| 45 | * Mock commits' comparison of a Github repository. | |
| 46 | * @author Andrej Istomin (andrej.istomin.ikeen@gmail.com) | |
| 47 | * @version $Id: b9ea4e747257933cc467b8449a3f4b0215e28f59 $ | |
| 48 | */ | |
| 49 | @Immutable | |
| 50 | @Loggable(Loggable.DEBUG) | |
| 51 | 0 | @ToString |
| 52 | final class MkCommitsComparison implements CommitsComparison { | |
| 53 | /** | |
| 54 | * File change JSON object. | |
| 55 | */ | |
| 56 | 2 | private static final JsonObject FILE_JSON = Json.createObjectBuilder() |
| 57 | 1 | .add("sha", "bbcd538c8e72b8c175046e27cc8f907076331401") |
| 58 | 1 | .add("filename", "test-file") |
| 59 | // @checkstyle MultipleStringLiterals (1 lines) | |
| 60 | 1 | .add("status", "modified") |
| 61 | 1 | .build(); |
| 62 | ||
| 63 | /** | |
| 64 | * Storage. | |
| 65 | */ | |
| 66 | private final transient MkStorage storage; | |
| 67 | ||
| 68 | /** | |
| 69 | * Login of the user logged in. | |
| 70 | */ | |
| 71 | private final transient String self; | |
| 72 | ||
| 73 | /** | |
| 74 | * Repo coordinates. | |
| 75 | */ | |
| 76 | private final transient Coordinates coords; | |
| 77 | ||
| 78 | /** | |
| 79 | * Public ctor. | |
| 80 | * @param stg Storage | |
| 81 | * @param login User to login | |
| 82 | * @param repo Repository coordinates | |
| 83 | */ | |
| 84 | MkCommitsComparison( | |
| 85 | final MkStorage stg, | |
| 86 | final String login, | |
| 87 | final Coordinates repo | |
| 88 | 5 | ) { |
| 89 | 5 | this.storage = stg; |
| 90 | 5 | this.self = login; |
| 91 | 5 | this.coords = repo; |
| 92 | 5 | } |
| 93 | ||
| 94 | @Override | |
| 95 | public Repo repo() { | |
| 96 | 4 | return new MkRepo(this.storage, this.self, this.coords); |
| 97 | } | |
| 98 | ||
| 99 | @Override | |
| 100 | public JsonObject json() throws IOException { | |
| 101 | 12 | return Json.createObjectBuilder() |
| 102 | // @checkstyle MultipleStringLiterals (3 lines) | |
| 103 | 4 | .add("status", "test-status") |
| 104 | 4 | .add("ahead_by", 1) |
| 105 | 4 | .add("behind_by", 2) |
| 106 | 4 | .add( |
| 107 | "author", | |
| 108 | 4 | Json.createObjectBuilder() |
| 109 | // @checkstyle MultipleStringLiterals (3 lines) | |
| 110 | 4 | .add("login", "test") |
| 111 | 4 | .build() |
| 112 | ) | |
| 113 | 4 | .add( |
| 114 | "files", | |
| 115 | 4 | Json.createArrayBuilder() |
| 116 | 4 | .add(MkCommitsComparison.FILE_JSON) |
| 117 | 4 | .build() |
| 118 | ) | |
| 119 | 4 | .add("commits", Json.createArrayBuilder().build()) |
| 120 | 4 | .build(); |
| 121 | } | |
| 122 | ||
| 123 | @Override | |
| 124 | public Iterable<FileChange> files() { | |
| 125 | 0 | return ImmutableList.<FileChange>of( |
| 126 | new MkFileChange(MkCommitsComparison.FILE_JSON) | |
| 127 | ); | |
| 128 | } | |
| 129 | } |