Package net.emaze.dysfunctional.consumers

Source Code of net.emaze.dysfunctional.consumers.ConsumeIntoCollectionTest

package net.emaze.dysfunctional.consumers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.emaze.dysfunctional.collections.ArrayListFactory;
import net.emaze.dysfunctional.dispatching.delegates.Delegate;
import org.junit.Assert;
import org.junit.Test;

/**
*
* @author rferranti
*/
public class ConsumeIntoCollectionTest {

    @Test
    public void consumingEmptyIteratorYieldsEmptyList() {
        List<Integer> consumable = Collections.emptyList();
        final ConsumeIntoCollection<ArrayList<Integer>, Integer> cons = new ConsumeIntoCollection<ArrayList<Integer>, Integer>(new ArrayListFactory<Integer>());
        ArrayList<Integer> got = cons.perform(consumable.iterator());
        Assert.assertEquals(consumable, got);
    }

    @Test
    public void consumingListYieldsSameValuesAsInList() {
        List<Integer> consumable = Arrays.asList(1, 2, 3);
        final ConsumeIntoCollection<ArrayList<Integer>, Integer> cons = new ConsumeIntoCollection<ArrayList<Integer>, Integer>(new ArrayListFactory<Integer>());
        ArrayList<Integer> got = cons.perform(consumable.iterator());
        Assert.assertEquals(consumable, got);
    }

    @Test(expected = IllegalArgumentException.class)
    public void consumingNullIteratorYieldException() {
        final ConsumeIntoCollection<ArrayList<Integer>, Integer> cons = new ConsumeIntoCollection<ArrayList<Integer>, Integer>(new ArrayListFactory<Integer>());
        cons.perform(null);
    }

    @Test(expected = IllegalArgumentException.class)
    public void creatingConsumerWithNullFactorYieldsException() {
        new ConsumeIntoCollection<ArrayList<Integer>, Integer>(null);

    }

    @Test(expected = ClassCastException.class)
    public void consumingFromErasureWithWrongTypeYieldsException() {
        final Delegate cons = new ConsumeIntoCollection<ArrayList<Integer>, Integer>(new ArrayListFactory<Integer>());
        cons.perform(new Object());
    }
}
TOP

Related Classes of net.emaze.dysfunctional.consumers.ConsumeIntoCollectionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.