/**
 * Copyright (c) 2013-2014, JCabi.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met: 1) Redistributions of source code must retain the above
 * copyright notice, this list of conditions and the following
 * disclaimer. 2) Redistributions in binary form must reproduce the above
 * copyright notice, this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided
 * with the distribution. 3) Neither the name of the jcabi.com nor
 * the names of its contributors may be used to endorse or promote
 * products derived from this software without specific prior written
 * permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package com.jcabi.github;

import javax.json.Json;
import org.apache.commons.lang3.RandomStringUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Test;

/**
 * Test case for {@link RtForks}.
 *
 * @author Carlos Miranda (miranda.cma@gmail.com)
 * @version $Id$
 */
public class RtForksITCase {

    /**
     * RtForks should be able to iterate its forks.
     *
     * @throws Exception if a problem occurs.
     */
    @Test
    public final void retrievesForks() throws Exception {
        final Iterable<Fork> forks = RtForksITCase.repos().get(
            new Coordinates.Simple(System.getProperty("failsafe.github.repo"))
        ).forks().iterate("newest");
        MatcherAssert.assertThat(forks, Matchers.notNullValue());
        MatcherAssert.assertThat(
            forks,
            Matchers.not(Matchers.emptyIterable())
        );
    }

    /**
     * RtForks should be able to create a new fork.
     *
     * @throws Exception if a problem occurs.
     */
    @Test
    public final void createsFork() throws Exception {
        final String organization = System.getProperty(
            "failsafe.github.organization"
        );
        Assume.assumeThat(organization, Matchers.notNullValue());
        final Repo repo = RtForksITCase.repos().create(
            Json.createObjectBuilder().add(
                // @checkstyle MagicNumber (1 line)
                "name", RandomStringUtils.randomNumeric(5)
            ).build()
        );
        try {
            final Fork fork = repo.forks().create(organization);
            MatcherAssert.assertThat(fork, Matchers.notNullValue());
        } finally {
            RtForksITCase.repos().remove(repo.coordinates());
        }
    }

    /**
     * Returns github repos.
     * @return Github repos.
     */
    private static Repos repos() {
        final String key = System.getProperty("failsafe.github.key");
        Assume.assumeThat(key, Matchers.notNullValue());
        return new RtGithub(key).repos();
    }

}

@@ -2173,215 +2173,149 @@
 nal 
-Iterable%3CFork%3E forks = RtForksITCase.repos().get(%0D%0A            new Coordinates.Simple(System.getProperty(%22failsafe.github.repo%22))%0D%0A        ).forks().iterate(%22newest%22);%0D%0A        MatcherAssert
+String organization = System.getProperty(%0D%0A                %22failsafe.github.organization%22%0D%0A        );%0D%0A        Assume
 .ass
-ert
+ume
 That(
-f
 or
-ks
+ganization
 , Ma
@@ -2351,32 +2351,54 @@
     
-MatcherAssert.assertTh
+final Repo repo = RtForksITCase.repos().cre
 at
+e
 (%0D%0A 
@@ -2412,368 +2412,278 @@
     
-forks,%0D%0A            Matchers.not(Matchers.emptyIterable())%0D%0A        );%0D%0A    %7D%0D%0A%0D%0A    /**%0D%0A     * RtForks should be able to create a new fork.
+    Json.createObjectBuilder().add(%0D%0A                        // @checkstyle MagicNumber (1 line)%0D%0A                        %22name%22, RandomStringUtils.randomNumeric(5)
 %0D%0A     
-*%0D%0A
      
-* @throws Exception if a problem occurs.%0D%0A     */%0D%0A    @Test%0D%0A    public final void createsFork() throws Exception %7B%0D%0A        final String organization = System.getProperty(%0D%0A            %22failsafe.github.
+      ).build()%0D%0A        );%0D%0A        try %7B%0D%0A            final Fork fork = repo.forks().create(
 orga
@@ -2682,33 +2682,34 @@
 ate(organization
-%22
+);
 %0D%0A        );%0D%0A  
@@ -2706,50 +2706,41 @@
     
-);%0D%0A        Assume
+    MatcherAssert
 .ass
-ume
+ert
 That(
+f
 or
-ganization
+k
 , Ma
@@ -2776,213 +2776,182 @@
     
+    
 final 
-Repo repo = RtForksITCase.repos().create(%0D%0A            Json.createObjectBuilder().add(%0D%0A                // @checkstyle MagicNumber (1 line)%0D%0A                %22name%22, RandomStringUtils.randomNumeric(5)
+Iterable%3CFork%3E forks = repo.forks().iterate(%22newest%22);%0D%0A            MatcherAssert.assertThat(forks, Matchers.notNullValue());%0D%0A            MatcherAssert.assertThat(
 %0D%0A  
@@ -2960,35 +2960,24 @@
         
-).build()%0D%0A
         
 );%0D%0A    
@@ -2960,34 +2960,38 @@
                 
-);
+forks,
 %0D%0A        try %7B%0D
@@ -2976,39 +2976,32 @@
 forks,%0D%0A        
-try %7B%0D%0A
             fina
@@ -3000,128 +3000,180 @@
     
-final Fork fork = repo.forks().create(organization);%0D%0A            MatcherAssert.assertThat(fork, Matchers.notNullValue()
+Matchers.not(Matchers.emptyIterable())%0D%0A            );%0D%0A            MatcherAssert.assertThat(%0D%0A                forks,%0D%0A                Matchers.contains(fork)%0D%0A            
 );%0D%0A

test recombination