001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.functor.core.algorithm;
018
019import static org.junit.Assert.assertFalse;
020import static org.junit.Assert.assertTrue;
021
022import java.util.Arrays;
023import java.util.List;
024
025import org.apache.commons.functor.BaseFunctorTest;
026import org.apache.commons.functor.Predicate;
027import org.apache.commons.functor.adapter.LeftBoundPredicate;
028import org.apache.commons.functor.core.IsEqual;
029import org.apache.commons.functor.core.algorithm.GeneratorContains;
030import org.apache.commons.functor.generator.loop.IteratorToGeneratorAdapter;
031import org.junit.Test;
032
033/**
034 * Tests {@link GeneratorContains} algorithm.
035 */
036public class TestGeneratorContains extends BaseFunctorTest {
037
038    @Override
039    protected Object makeFunctor() throws Exception {
040        return new GeneratorContains<Integer>();
041    }
042
043    @Test
044    public void testContains() {
045        assertTrue(new GeneratorContains<Integer>()
046            .test(IteratorToGeneratorAdapter.adapt(list.iterator()), equalsThree));
047        assertFalse(new GeneratorContains<Integer>().test(IteratorToGeneratorAdapter.adapt(list.iterator()),
048            equalsTwentyThree));
049    }
050
051    // Attributes
052    // ------------------------------------------------------------------------
053
054    private List<Integer> list = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
055    private Predicate<Integer> equalsThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(3));
056    private Predicate<Integer> equalsTwentyThree = LeftBoundPredicate.bind(IsEqual.instance(), Integer.valueOf(23));
057
058}