Coverage Report - com.jcabi.github.RtComment
 
Classes in this File Line Coverage Branch Coverage Complexity
RtComment
88%
16/18
0%
0/18
1
RtComment$AjcClosure1
100%
1/1
N/A
1
RtComment$AjcClosure11
100%
1/1
N/A
1
RtComment$AjcClosure3
100%
1/1
N/A
1
RtComment$AjcClosure5
100%
1/1
N/A
1
RtComment$AjcClosure7
100%
1/1
N/A
1
RtComment$AjcClosure9
100%
1/1
N/A
1
 
 1  2
 /**
 2  
  * Copyright (c) 2013-2015, 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;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import com.jcabi.http.Request;
 35  
 import com.jcabi.http.response.RestResponse;
 36  
 import java.io.IOException;
 37  
 import java.net.HttpURLConnection;
 38  
 import javax.json.JsonObject;
 39  
 import javax.validation.constraints.NotNull;
 40  
 import lombok.EqualsAndHashCode;
 41  
 
 42  
 /**
 43  
  * Github comment.
 44  
  *
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id$
 47  
  * @since 0.1
 48  
  */
 49  0
 @Immutable
 50  
 @Loggable(Loggable.DEBUG)
 51  0
 @EqualsAndHashCode(of = { "request", "owner", "num" })
 52  
 final class RtComment implements Comment {
 53  
 
 54  
     /**
 55  
      * RESTful request.
 56  
      */
 57  
     private final transient Request request;
 58  
 
 59  
     /**
 60  
      * Issue we're in.
 61  
      */
 62  
     private final transient Issue owner;
 63  
 
 64  
     /**
 65  
      * Comment number.
 66  
      */
 67  
     private final transient int num;
 68  
 
 69  
     /**
 70  
      * Public ctor.
 71  
      * @param req RESTful request
 72  
      * @param issue Owner of this comment
 73  
      * @param number Number of the get
 74  
      */
 75  8
     RtComment(final Request req, final Issue issue, final int number) {
 76  8
         final Coordinates coords = issue.repo().coordinates();
 77  8
         this.request = req.uri()
 78  
             .path("/repos")
 79  
             .path(coords.user())
 80  
             .path(coords.repo())
 81  
             .path("/issues")
 82  
             .path("/comments")
 83  
             .path(Integer.toString(number))
 84  
             .back();
 85  8
         this.owner = issue;
 86  8
         this.num = number;
 87  8
     }
 88  
 
 89  
     @Override
 90  
     @NotNull(message = "toString is never NULL")
 91  
     public String toString() {
 92  1
         return this.request.uri().get().toString();
 93  
     }
 94  
 
 95  
     @Override
 96  
     @NotNull(message = "Issue is never NULL")
 97  
     public Issue issue() {
 98  2
         return this.owner;
 99  
     }
 100  
 
 101  
     @Override
 102  
     public int number() {
 103  10
         return this.num;
 104  
     }
 105  
 
 106  
     @Override
 107  
     public void remove() throws IOException {
 108  2
         this.request.method(Request.DELETE).fetch()
 109  
             .as(RestResponse.class)
 110  
             .assertStatus(HttpURLConnection.HTTP_NO_CONTENT);
 111  1
     }
 112  
 
 113  
     @Override
 114  
     @NotNull(message = "JSON is never NULL")
 115  
     public JsonObject json() throws IOException {
 116  2
         return new RtJson(this.request).fetch();
 117  
     }
 118  
 
 119  
     @Override
 120  
     public void patch(@NotNull(message = "JSON can't be NULL")
 121  
         final JsonObject json) throws IOException {
 122  2
         new RtJson(this.request).patch(json);
 123  1
     }
 124  
 
 125  
     @Override
 126  
     public int compareTo(
 127  
         @NotNull(message = "comment is never NULL") final Comment comment
 128  
     ) {
 129  4
         return this.number() - comment.number();
 130  
     }
 131  
 }