Coverage Report - com.jcabi.github.RtAssignees
 
Classes in this File Line Coverage Branch Coverage Complexity
RtAssignees
92%
24/26
6%
2/30
1
RtAssignees$1
100%
5/5
N/A
1
RtAssignees$AjcClosure1
100%
1/1
N/A
1
RtAssignees$AjcClosure3
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  
 import org.hamcrest.Matchers;
 41  
 
 42  
 /**
 43  
  * Github Assignees.
 44  
  *
 45  
  * @author Paul Polishchuk (ppol@ua.fm)
 46  
  * @version $Id: 8cbe34c065b9b4cbc66dd17a332e80b9218339e0 $
 47  
  * @since 0.7
 48  
  * @checkstyle MultipleStringLiterals (500 lines)
 49  
  */
 50  
 @Immutable
 51  
 @Loggable(Loggable.DEBUG)
 52  0
 @EqualsAndHashCode(of = { "entry", "request", "owner" })
 53  4
 final class RtAssignees implements Assignees {
 54  
 
 55  
     /**
 56  
      * API entry point.
 57  
      */
 58  
     private final transient Request entry;
 59  
 
 60  
     /**
 61  
      * RESTful request.
 62  
      */
 63  
     private final transient Request request;
 64  
 
 65  
     /**
 66  
      * Repository we're in.
 67  
      */
 68  
     private final transient Repo owner;
 69  
 
 70  
     /**
 71  
      * Public ctor.
 72  
      * @param repo Repo
 73  
      * @param req Request
 74  
      */
 75  3
     RtAssignees(final Request req, final Repo repo) {
 76  3
         this.entry = req;
 77  3
         final Coordinates coords = repo.coordinates();
 78  3
         this.request = this.entry.uri()
 79  3
             .path("/repos")
 80  3
             .path(coords.user())
 81  3
             .path(coords.repo())
 82  3
             .path("/assignees")
 83  3
             .back();
 84  3
         this.owner = repo;
 85  3
     }
 86  
 
 87  
     @Override
 88  
     public Iterable<User> iterate() {
 89  2
         return new RtPagination<User>(
 90  
             this.request,
 91  3
             new RtValuePagination.Mapping<User, JsonObject>() {
 92  
                 @Override
 93  
                 public User map(final JsonObject object) {
 94  4
                     return new RtUser(
 95  2
                         RtAssignees.this.owner.github(),
 96  2
                         RtAssignees.this.entry,
 97  2
                         object.getString("login")
 98  
                     );
 99  
                 }
 100  
             }
 101  
         );
 102  
     }
 103  
 
 104  
     @Override
 105  
     public boolean check(
 106  
         final String login
 107  
     ) throws IOException {
 108  6
         return this.request
 109  2
             .method(Request.GET)
 110  2
             .uri().path(login).back()
 111  2
             .fetch()
 112  2
             .as(RestResponse.class)
 113  2
             .assertStatus(
 114  2
                 Matchers.isOneOf(
 115  2
                     HttpURLConnection.HTTP_NO_CONTENT,
 116  2
                     HttpURLConnection.HTTP_NOT_FOUND
 117  
                 )
 118  2
             ).status() == HttpURLConnection.HTTP_NO_CONTENT;
 119  
     }
 120  
 
 121  
     @Override
 122  
     public String toString() {
 123  0
         return this.request.uri().get().toString();
 124  
     }
 125  
 }