Coverage Report - com.jcabi.github.mock.MkSearch
 
Classes in this File Line Coverage Branch Coverage Complexity
MkSearch
69%
9/13
0%
0/16
1.6
MkSearch$1
50%
1/2
N/A
1.6
MkSearch$2
50%
1/2
N/A
1.6
MkSearch$3
25%
1/4
N/A
1.6
MkSearch$4
25%
1/4
N/A
1.6
MkSearch$AjcClosure1
0%
0/1
N/A
1.6
MkSearch$AjcClosure3
100%
1/1
N/A
1.6
MkSearch$AjcClosure5
100%
1/1
N/A
1.6
MkSearch$AjcClosure7
100%
1/1
N/A
1.6
MkSearch$AjcClosure9
100%
1/1
N/A
1.6
 
 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.mock;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import com.jcabi.aspects.Loggable;
 34  
 import com.jcabi.github.Content;
 35  
 import com.jcabi.github.Coordinates;
 36  
 import com.jcabi.github.Github;
 37  
 import com.jcabi.github.Issue;
 38  
 import com.jcabi.github.Repo;
 39  
 import com.jcabi.github.Search;
 40  
 import com.jcabi.github.User;
 41  
 import com.jcabi.xml.XML;
 42  
 import java.io.IOException;
 43  
 import java.util.EnumMap;
 44  
 import javax.validation.constraints.NotNull;
 45  
 import lombok.EqualsAndHashCode;
 46  
 import lombok.ToString;
 47  
 
 48  
 /**
 49  
  * Mock Github search.
 50  
  *
 51  
  * @author Carlos Miranda (miranda.cma@gmail.com)
 52  
  * @version $Id$
 53  
  * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
 54  
  */
 55  
 @Immutable
 56  
 @Loggable(Loggable.DEBUG)
 57  0
 @ToString
 58  0
 @EqualsAndHashCode(of = { "storage", "self" })
 59  0
 final class MkSearch implements Search {
 60  
 
 61  
     /**
 62  
      * Storage.
 63  
      */
 64  
     private final transient MkStorage storage;
 65  
 
 66  
     /**
 67  
      * Login of the user logged in.
 68  
      */
 69  
     private final transient String self;
 70  
 
 71  
     /**
 72  
      * Public ctor.
 73  
      *
 74  
      * @param stg Storage
 75  
      * @param login User to login
 76  
      */
 77  
     MkSearch(
 78  
         @NotNull(message = "stg can't be NULL") final MkStorage stg,
 79  
         @NotNull(message = "login can't be NULL") final String login
 80  4
     ) {
 81  4
         this.storage = stg;
 82  4
         this.self = login;
 83  4
     }
 84  
 
 85  
     @Override
 86  
     @NotNull(message = "github is never NULL")
 87  
     public Github github() {
 88  0
         return new MkGithub(this.storage, this.self);
 89  
     }
 90  
 
 91  
     @Override
 92  
     @NotNull(message = "Iterable of repos is never NULL")
 93  
     public Iterable<Repo> repos(
 94  
         @NotNull(message = "keywords can't be NULL") final String keywords,
 95  
         @NotNull(message = "sort can't be NULL") final String sort,
 96  
         @NotNull(message = "order can't be NULL") final Order order
 97  
     ) throws IOException {
 98  2
         return new MkIterable<Repo>(
 99  
             this.storage,
 100  
             "/github/repos/repo",
 101  1
             new MkIterable.Mapping<Repo>() {
 102  
                 @Override
 103  
                 public Repo map(final XML xml) {
 104  0
                     return new MkRepo(
 105  
                         MkSearch.this.storage, MkSearch.this.self,
 106  
                         new Coordinates.Simple(xml.xpath("@coords").get(0))
 107  
                     );
 108  
                 }
 109  
             }
 110  
         );
 111  
     }
 112  
 
 113  
     //@checkstyle ParameterNumberCheck (5 lines)
 114  
     @Override
 115  
     @NotNull(message = "Iterable of issues is never NULL")
 116  
     public Iterable<Issue> issues(final String keywords, final String sort,
 117  
         final Order order, final EnumMap<Qualifier, String> qualifiers
 118  
     ) throws IOException {
 119  2
         return new MkIterable<Issue>(
 120  
             this.storage,
 121  
             "/github/repos/repo/issues/issue",
 122  1
             new MkIterable.Mapping<Issue>() {
 123  
                 @Override
 124  
                 public Issue map(final XML xml) {
 125  0
                     return new MkIssue(
 126  
                         MkSearch.this.storage, MkSearch.this.self,
 127  
                         new Coordinates.Simple(
 128  
                             xml.xpath("../../@coords").get(0)
 129  
                         ),
 130  
                         Integer.parseInt(xml.xpath("number/text()").get(0))
 131  
                     );
 132  
                 }
 133  
             }
 134  
         );
 135  
     }
 136  
 
 137  
     @Override
 138  
     @NotNull(message = "iterable of users is never NULL")
 139  
     public Iterable<User> users(
 140  
         @NotNull(message = "keywords shouldn't be NULL") final String keywords,
 141  
         @NotNull(message = "sort shouldn't be NULL") final String sort,
 142  
         @NotNull(message = "order shouldn't be NULL") final Order order
 143  
     ) throws IOException {
 144  2
         return new MkIterable<User>(
 145  
             this.storage,
 146  
             "/github/users/user",
 147  1
             new MkIterable.Mapping<User>() {
 148  
                 @Override
 149  
                 public User map(final XML xml) {
 150  
                     try {
 151  0
                         return new MkUser(
 152  
                             MkSearch.this.storage,
 153  
                             xml.xpath("login/text()").get(0)
 154  
                         );
 155  0
                     } catch (final IOException ex) {
 156  0
                         throw new IllegalStateException(ex);
 157  
                     }
 158  
                 }
 159  
             }
 160  
         );
 161  
     }
 162  
 
 163  
     @Override
 164  
     @NotNull(message = "iterable of contents is never NULL")
 165  
     public Iterable<Content> codes(
 166  
         @NotNull(message = "keywords shouldn't be NULL") final String keywords,
 167  
         @NotNull(message = "sort shouldn't be NULL") final String sort,
 168  
         @NotNull(message = "order shouldn't be NULL") final Order order
 169  
     ) throws IOException {
 170  2
         return new MkIterable<Content>(
 171  
             this.storage,
 172  
             "/github/repos/repo/name",
 173  1
             new MkIterable.Mapping<Content>() {
 174  
                 @Override
 175  
                 public Content map(final XML xml) {
 176  
                     try {
 177  0
                         return new MkContent(
 178  
                             MkSearch.this.storage,
 179  
                             MkSearch.this.self,
 180  
                             new Coordinates.Simple(MkSearch.this.self, "repo"),
 181  
                             "/path/to/search",
 182  
                             "master"
 183  
                         );
 184  0
                     } catch (final IOException exception) {
 185  0
                         throw new IllegalStateException(exception);
 186  
                     }
 187  
                 }
 188  
             }
 189  
         );
 190  
     }
 191  
 
 192  
 }