Coverage Report - com.jcabi.github.mock.MkUsers
 
Classes in this File Line Coverage Branch Coverage Complexity
MkUsers
57%
8/14
0%
0/16
1.5
MkUsers$1
0%
0/2
N/A
1.5
MkUsers$AjcClosure1
0%
0/1
N/A
1.5
MkUsers$AjcClosure3
100%
1/1
N/A
1.5
MkUsers$AjcClosure5
100%
1/1
N/A
1.5
MkUsers$AjcClosure7
0%
0/1
N/A
1.5
 
 1  0
 /**
 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.Github;
 35  
 import com.jcabi.github.User;
 36  
 import com.jcabi.github.Users;
 37  
 import com.jcabi.xml.XML;
 38  
 import java.io.IOException;
 39  
 import javax.validation.constraints.NotNull;
 40  
 import lombok.EqualsAndHashCode;
 41  
 import lombok.ToString;
 42  
 import org.xembly.Directives;
 43  
 
 44  
 /**
 45  
  * Mock Github users.
 46  
  *
 47  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 48  
  * @version $Id$
 49  
  * @since 0.5
 50  
  */
 51  
 @Immutable
 52  
 @Loggable(Loggable.DEBUG)
 53  0
 @ToString
 54  0
 @EqualsAndHashCode(of = { "storage", "himself" })
 55  
 final class MkUsers implements Users {
 56  
 
 57  
     /**
 58  
      * Storage.
 59  
      */
 60  
     private final transient MkStorage storage;
 61  
 
 62  
     /**
 63  
      * Login of the user logged in.
 64  
      */
 65  
     private final transient String himself;
 66  
 
 67  
     /**
 68  
      * Public ctor.
 69  
      * @param stg Storage
 70  
      * @param login User to login
 71  
      * @throws IOException If there is any I/O problem
 72  
      */
 73  
     MkUsers(
 74  
         @NotNull(message = "stg can't be NULL") final MkStorage stg,
 75  
         @NotNull(message = "login can't be NULL") final String login
 76  28
     ) throws IOException {
 77  28
         this.storage = stg;
 78  28
         this.himself = login;
 79  28
         this.storage.apply(
 80  
             new Directives().xpath("/github").addIf("users")
 81  
         );
 82  28
     }
 83  
 
 84  
     @Override
 85  
     @NotNull(message = "Github is never NULL")
 86  
     public Github github() {
 87  0
         return new MkGithub(this.storage, this.himself);
 88  
     }
 89  
 
 90  
     @Override
 91  
     @NotNull(message = "self is never NULL")
 92  
     public User self() {
 93  12
         return this.get(this.himself);
 94  
     }
 95  
 
 96  
     @Override
 97  
     @NotNull(message = "user is never NULL")
 98  
     public User get(
 99  
         @NotNull(message = "login is never NULL") final String login
 100  
     ) {
 101  
         try {
 102  56
             return new MkUser(this.storage, login);
 103  0
         } catch (final IOException ex) {
 104  0
             throw new IllegalStateException(ex);
 105  
         }
 106  
     }
 107  
 
 108  
     @Override
 109  
     @NotNull(message = "Iterable is never NULL")
 110  
     public Iterable<User> iterate(
 111  
         @NotNull(message = "identifier is never NULL") final String identifier
 112  
     ) {
 113  0
         return new MkIterable<User>(
 114  
             this.storage,
 115  
             "/github/users/user",
 116  0
             new MkIterable.Mapping<User>() {
 117  
                 @Override
 118  
                 public User map(final XML xml) {
 119  0
                     return MkUsers.this.get(xml.xpath("login/text()").get(0));
 120  
                 }
 121  
             }
 122  
         );
 123  
     }
 124  
 
 125  
 }