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