Package net.emaze.dysfunctional.consumers

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

package net.emaze.dysfunctional.consumers;

import java.util.Arrays;
import java.util.List;
import junit.framework.Assert;
import net.emaze.dysfunctional.dispatching.delegates.Delegate;
import net.emaze.dysfunctional.output.StringOutputIterator;
import org.junit.Test;

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

    @Test
    public void testThatCanConsume() {
        final List<String> input = Arrays.asList("1","2","3","4","5");
        final StringOutputIterator output = new StringOutputIterator();
        final ConsumeIntoOutputIterator<String> pipe = new ConsumeIntoOutputIterator<String>(output);
        pipe.perform(input.iterator());
        Assert.assertEquals("12345", output.toString());
    }

    @Test
    public void testThatCanConsumeEmptyList() {
        final List<String> input = Arrays.<String>asList();
        final StringOutputIterator output = new StringOutputIterator();
        final ConsumeIntoOutputIterator<String> pipe = new ConsumeIntoOutputIterator<String>(output);
        pipe.perform(input.iterator());
        Assert.assertEquals("", output.toString());
    }

    @Test(expected = IllegalArgumentException.class)
    public void consumingNullIteratorYieldException() {
        final StringOutputIterator output = new StringOutputIterator();
        new ConsumeIntoOutputIterator<String>(output).perform(null);
    }
   
    @Test(expected = IllegalArgumentException.class)
    public void nullOutputIteratorYieldException() {
        new ConsumeIntoOutputIterator<String>(null);
    }
   
    @Test(expected = ClassCastException.class)
    public void consumingFromErasureWithWrongTypeYieldsException() {
        final StringOutputIterator output = new StringOutputIterator();
        Delegate pipe = new ConsumeIntoOutputIterator(output);
        pipe.perform(new Object());
    }   
}
TOP

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

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.