Coverage Report - com.jcabi.github.safe.SfComment
 
Classes in this File Line Coverage Branch Coverage Complexity
SfComment
0%
0/31
0%
0/12
1.375
SfComment$AjcClosure1
0%
0/1
N/A
1.375
SfComment$AjcClosure11
0%
0/1
N/A
1.375
SfComment$AjcClosure3
0%
0/1
N/A
1.375
SfComment$AjcClosure5
0%
0/1
N/A
1.375
SfComment$AjcClosure7
0%
0/1
N/A
1.375
SfComment$AjcClosure9
0%
0/1
N/A
1.375
 
 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.safe;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import com.jcabi.github.Comment;
 35  
 import com.jcabi.github.Issue;
 36  
 import com.jcabi.github.mock.MkGithub;
 37  
 import com.jcabi.log.Logger;
 38  
 import java.io.IOException;
 39  
 import javax.json.JsonObject;
 40  
 import lombok.EqualsAndHashCode;
 41  
 
 42  
 /**
 43  
  * Safe comment.
 44  
  *
 45  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 46  
  * @version $Id: 7829642fb372b4ffc3f2a6e815bace075944ea82 $
 47  
  * @since 0.34
 48  
  */
 49  0
 @Immutable
 50  
 @Loggable(Loggable.DEBUG)
 51  0
 @EqualsAndHashCode(of = "origin")
 52  
 public final class SfComment implements Comment {
 53  
 
 54  
     /**
 55  
      * Original comment.
 56  
      */
 57  
     private final transient Comment origin;
 58  
 
 59  
     /**
 60  
      * Public ctor.
 61  
      * @param cmt The original comment
 62  
      */
 63  0
     public SfComment(final Comment cmt) {
 64  0
         this.origin = cmt;
 65  0
     }
 66  
 
 67  
     @Override
 68  
     public String toString() {
 69  0
         return this.origin.toString();
 70  
     }
 71  
 
 72  
     @Override
 73  
     public Issue issue() {
 74  0
         return this.origin.issue();
 75  
     }
 76  
 
 77  
     @Override
 78  
     public int number() {
 79  0
         return this.origin.number();
 80  
     }
 81  
 
 82  
     @Override
 83  
     public void remove() throws IOException {
 84  
         try {
 85  0
             this.origin.remove();
 86  0
         } catch (final AssertionError ex) {
 87  0
             Logger.warn(this, "Failed to remove comment: %[exception]s", ex);
 88  0
         }
 89  0
     }
 90  
 
 91  
     @Override
 92  
     public int compareTo(final Comment cmt) {
 93  0
         return this.origin.compareTo(cmt);
 94  
     }
 95  
 
 96  
     @Override
 97  
     public void patch(final JsonObject json) throws IOException {
 98  
         try {
 99  0
             this.origin.patch(json);
 100  0
         } catch (final AssertionError ex) {
 101  0
             Logger.warn(this, "Failed to path comment: %[exception]s", ex);
 102  0
         }
 103  0
     }
 104  
 
 105  
     @Override
 106  
     public JsonObject json() throws IOException {
 107  
         JsonObject json;
 108  
         try {
 109  0
             json = this.origin.json();
 110  0
         } catch (final AssertionError ex) {
 111  0
             final String author = new Issue.Smart(
 112  0
                 new SfIssue(this.origin.issue())
 113  0
             ).author().login();
 114  0
             json = new MkGithub(author).randomRepo()
 115  0
                 .issues().create("", "")
 116  0
                 .comments().post("deleted comment").json();
 117  0
             Logger.warn(this, "failed to fetch comment: %[exception]s", ex);
 118  0
         }
 119  0
         return json;
 120  
     }
 121  
 }