Coverage Report - com.jcabi.github.mock.MkOrganizations
 
Classes in this File Line Coverage Branch Coverage Complexity
MkOrganizations
80%
17/21
0%
0/12
1.4
MkOrganizations$1
33%
1/3
N/A
1.4
MkOrganizations$AjcClosure1
100%
1/1
N/A
1.4
MkOrganizations$AjcClosure3
100%
1/1
N/A
1.4
 
 1  28
 /**
 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.Organization;
 35  
 import com.jcabi.github.Organizations;
 36  
 import com.jcabi.xml.XML;
 37  
 import java.io.IOException;
 38  
 import lombok.EqualsAndHashCode;
 39  
 import lombok.ToString;
 40  
 import org.xembly.Directives;
 41  
 
 42  
 /**
 43  
  * Github organizations.
 44  
  * @author Paul Polishchuk (ppol@ua.fm)
 45  
  * @version $Id: 1762ad158c35927c15130dc189bafbb6b8ebae7b $
 46  
  * @see <a href="http://developer.github.com/v3/orgs/">Organizations API</a>
 47  
  * @since 0.24
 48  
  */
 49  
 @Immutable
 50  
 @Loggable(Loggable.DEBUG)
 51  0
 @ToString
 52  0
 @EqualsAndHashCode(of = { "storage" })
 53  
 final class MkOrganizations implements Organizations {
 54  
     /**
 55  
      * Storage.
 56  
      */
 57  
     private final transient MkStorage storage;
 58  
 
 59  
     /**
 60  
      * Public ctor.
 61  
      * @param stg Storage
 62  
      * @throws IOException If there is any I/O problem
 63  
      */
 64  
     MkOrganizations(
 65  
         final MkStorage stg
 66  
     )
 67  10
         throws IOException {
 68  10
         this.storage = stg;
 69  20
         this.storage.apply(
 70  10
             new Directives().xpath("/github").addIf("orgs")
 71  
         );
 72  10
     }
 73  
 
 74  
     @Override
 75  
     public Organization get(
 76  
         final String login
 77  
     ) {
 78  
         try {
 79  42
             this.storage.apply(
 80  
                 new Directives()
 81  14
                     .xpath(
 82  14
                         String.format(
 83  
                             "/github/orgs[not(org[login='%s'])]",
 84  
                             login
 85  
                     )
 86  
                 )
 87  14
                     .add("org")
 88  14
                     .add("login").set(login).up()
 89  14
                     .add("members").up()
 90  
             );
 91  0
         } catch (final IOException ex) {
 92  0
             throw new IllegalStateException(ex);
 93  14
         }
 94  14
         return new MkOrganization(this.storage, login);
 95  
     }
 96  
 
 97  
     @Override
 98  
     public Iterable<Organization> iterate() {
 99  3
         return new MkIterable<Organization>(
 100  
             this.storage,
 101  1
             String.format("%s/org", this.xpath()),
 102  1
             new MkIterable.Mapping<Organization>() {
 103  
                 @Override
 104  
                 public Organization map(final XML xml) {
 105  0
                     return MkOrganizations.this.get(
 106  0
                         xml.xpath("login/text()").get(0)
 107  
                     );
 108  
                 }
 109  
             }
 110  
         );
 111  
     }
 112  
 
 113  
     /**
 114  
      * XPath of this element in XML tree.
 115  
      * @return XPath
 116  
      */
 117  
     private String xpath() {
 118  1
         return "/github/orgs";
 119  
     }
 120  
 }