Coverage Report - com.jcabi.github.RtComment
 
Classes in this File Line Coverage Branch Coverage Complexity
RtComment
92%
25/27
0%
0/22
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-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;
 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 lombok.EqualsAndHashCode;
 40  
 
 41  
 /**
 42  
  * Github comment.
 43  
  *
 44  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 45  
  * @version $Id: 77eef51254cd18c9977801ed121feae83753f2d2 $
 46  
  * @since 0.1
 47  
  */
 48  0
 @Immutable
 49  
 @Loggable(Loggable.DEBUG)
 50  0
 @EqualsAndHashCode(of = { "request", "owner", "num" })
 51  
 final class RtComment implements Comment {
 52  
 
 53  
     /**
 54  
      * RESTful request.
 55  
      */
 56  
     private final transient Request request;
 57  
 
 58  
     /**
 59  
      * Issue we're in.
 60  
      */
 61  
     private final transient Issue owner;
 62  
 
 63  
     /**
 64  
      * Comment number.
 65  
      */
 66  
     private final transient int num;
 67  
 
 68  
     /**
 69  
      * Public ctor.
 70  
      * @param req RESTful request
 71  
      * @param issue Owner of this comment
 72  
      * @param number Number of the get
 73  
      */
 74  8
     RtComment(final Request req, final Issue issue, final int number) {
 75  8
         final Coordinates coords = issue.repo().coordinates();
 76  8
         this.request = req.uri()
 77  8
             .path("/repos")
 78  8
             .path(coords.user())
 79  8
             .path(coords.repo())
 80  8
             .path("/issues")
 81  8
             .path("/comments")
 82  8
             .path(Integer.toString(number))
 83  8
             .back();
 84  8
         this.owner = issue;
 85  8
         this.num = number;
 86  8
     }
 87  
 
 88  
     @Override
 89  
     public String toString() {
 90  1
         return this.request.uri().get().toString();
 91  
     }
 92  
 
 93  
     @Override
 94  
     public Issue issue() {
 95  2
         return this.owner;
 96  
     }
 97  
 
 98  
     @Override
 99  
     public int number() {
 100  10
         return this.num;
 101  
     }
 102  
 
 103  
     @Override
 104  
     public void remove() throws IOException {
 105  2
         this.request.method(Request.DELETE).fetch()
 106  1
             .as(RestResponse.class)
 107  1
             .assertStatus(HttpURLConnection.HTTP_NO_CONTENT);
 108  1
     }
 109  
 
 110  
     @Override
 111  
     public JsonObject json() throws IOException {
 112  2
         return new RtJson(this.request).fetch();
 113  
     }
 114  
 
 115  
     @Override
 116  
     public void patch(final JsonObject json) throws IOException {
 117  2
         new RtJson(this.request).patch(json);
 118  1
     }
 119  
 
 120  
     @Override
 121  
     public int compareTo(
 122  
         final Comment comment
 123  
     ) {
 124  4
         return this.number() - comment.number();
 125  
     }
 126  
 }