/**
 * The MIT License (MIT)
 *
 * Copyright (c) 2017 Yegor Bugayenko
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.cactoos.func;

import java.security.SecureRandom;
import org.cactoos.Func;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
 * Test case for {@link RepeatedFunc}.
 *
 * @author Yegor Bugayenko (yegor256@gmail.com)
 * @author Ix (ixmanuel@yahoo.com)
 * @version $Id$
 * @since 0.6
 * @checkstyle JavadocMethodCheck (500 lines)
 */
public final class RepeatedFuncTest {

    @Test
    public void runsFuncMultipleTimes() throws Exception {
        final Func<Boolean, Integer> func = new RepeatedFunc<>(
            input -> {
                return new SecureRandom().nextInt();
            },
            2
        );
        MatcherAssert.assertThat(
            func.apply(true),
            Matchers.not(Matchers.equalTo(func.apply(true)))
        );
    }

    @Test(expected = IllegalStateException.class)
    public void failsToRepeatNulls() throws Exception {
        final Func<Boolean, Integer> func = new RepeatedFunc<>(
            input -> {
                return null;
            },
            2
        );
        MatcherAssert.assertThat(
            func.apply(true),
            Matchers.not(Matchers.equalTo(func.apply(true)))
        );
    }

    @Test(expected = IndexOutOfBoundsException.class)
    public void doesntRepeatAny() throws Exception {
        final Func<Boolean, Integer> func = new RepeatedFunc<>(
            input -> {
                return new SecureRandom().nextInt();
            },
            0
        );
        MatcherAssert.assertThat(
            func.apply(true),
            Matchers.equalTo(func.apply(true))
        );
    }

}

@@ -1205,16 +1205,66 @@
 Random;%0A
+import java.util.concurrent.atomic.AtomicInteger;%0A
 import o
@@ -1697,36 +1697,136 @@
       final 
-Func%3CBoolean
+Integer repeated = 2;%0A        final AtomicInteger count = new AtomicInteger(0);%0A        final Func%3CAtomicInteger
 , Integer%3E f
@@ -1901,33 +1901,28 @@
 urn 
-new SecureRandom().nextIn
+count.incrementAndGe
 t();
@@ -1941,33 +1941,40 @@
  %7D,%0A            
-2
+repeated
 %0A        );%0A    
@@ -2018,36 +2018,37 @@
      func.apply(
-true
+count
 ),%0A            M
@@ -2042,37 +2042,24 @@
             
-Matchers.not(
 Matchers.equ
@@ -2063,33 +2063,24 @@
 equalTo(
-func.apply(true))
+repeated
 )%0A      

Fix RepeatedFuncTest does not test multiple runs #375