/**
 * 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.scalar;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.cactoos.Scalar;
import org.cactoos.ScalarHasValue;
import org.cactoos.func.FuncOf;
import org.cactoos.func.MatcherOf;
import org.cactoos.iterable.IterableOf;
import org.cactoos.iterable.Mapped;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
 * Test case for {@link And}.
 *
 * @author Vseslav Sekorin (vssekorin@gmail.com)
 * @version $Id$
 * @since 0.8
 * @checkstyle JavadocMethodCheck (500 lines)
 * @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
 */
public final class AndTest {

    @Test
    public void allTrue() throws Exception {
        MatcherAssert.assertThat(
            new And(
                new True(),
                new True(),
                new True()
            ).value(),
            Matchers.equalTo(true)
        );
    }

    @Test
    public void oneFalse() throws Exception {
        MatcherAssert.assertThat(
            new And(
                new True(),
                new False(),
                new True()
            ).value(),
            Matchers.equalTo(false)
        );
    }

    @Test
    public void allFalse() throws Exception {
        MatcherAssert.assertThat(
            new And(
                new IterableOf<Scalar<Boolean>>(
                    new False(),
                    new False(),
                    new False()
                )
            ).value(),
            Matchers.equalTo(false)
        );
    }

    @Test
    public void emptyIterator() throws Exception {
        MatcherAssert.assertThat(
            new And(Collections.emptyList()).value(),
            Matchers.equalTo(true)
        );
    }

    @Test
    public void iteratesList() {
        final List<String> list = new LinkedList<>();
        MatcherAssert.assertThat(
            "Can't iterate a list with a procedure",
            new And(
                new Mapped<String, Scalar<Boolean>>(
                    new IterableOf<>("hello", "world"),
                    new FuncOf<>(list::add, () -> true)
                )
            ),
            new ScalarHasValue<>(
                Matchers.allOf(
                    Matchers.equalTo(true),
                    new MatcherOf<>(
                        value -> list.size() == 2
                    )
                )
            )
        );
    }

    @Test
    public void iteratesEmptyList() {
        final List<String> list = new LinkedList<>();
        MatcherAssert.assertThat(
            "Can't iterate a list",
            new And(
                new Mapped<String, Scalar<Boolean>>(
                    Collections.emptyList(),
                    new FuncOf<>(list::add, () -> true)
                )
            ),
            new ScalarHasValue<>(
                Matchers.allOf(
                    Matchers.equalTo(true),
                    new MatcherOf<>(
                        value -> {
                            return list.isEmpty();
                        }
                    )
                )
            )
        );
    }

}

@@ -1250,24 +1250,49 @@
 .util.List;%0A
+import org.cactoos.Proc;%0A
 import org.c
@@ -1607,19 +1607,16 @@
 k And%7D.%0A
- *%0A
  * @auth
@@ -1656,16 +1656,63 @@
 il.com)%0A
+ * @author Mehmet Yildirim (memoyil@gmail.com)%0A
  * @vers
@@ -4354,10 +4354,571 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testProc() throws Exception %7B%0A        final List%3CInteger%3E list = new LinkedList%3C%3E();%0A        new And(%0A            (Proc%3CInteger%3E) list::add,%0A            1, 1%0A        ).value();%0A        MatcherAssert.assertThat(%0A            list.size(),%0A            Matchers.equalTo(2)%0A        );%0A    %7D%0A%0A    @Test%0A    public void testFunc() throws Exception %7B%0A        MatcherAssert.assertThat(%0A            new And(%0A                input -%3E input %3E 0,%0A                1, -1, 0%0A            ).value(),%0A            Matchers.equalTo(false)%0A        );%0A    %7D%0A%0A
 %7D%0A

Add AndTestCases #392