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