Package net.emaze.dysfunctional.reductions

Source Code of net.emaze.dysfunctional.reductions.ReductorTest

package net.emaze.dysfunctional.reductions;

import net.emaze.dysfunctional.dispatching.delegates.Delegate;
import net.emaze.dysfunctional.iterations.ArrayIterator;
import org.junit.Assert;
import org.junit.Test;

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

    @Test
    public void canReduceAnIterator() {
        Integer[] arr = new Integer[]{1, 2, 3, 4};
        Reductor<Long, Integer> cc = new Reductor<Long, Integer>(new Count<Integer>(), 0l);
        long count = cc.perform(new ArrayIterator<Integer>(arr));
        Assert.assertEquals(4l, count);
    }

    @Test(expected = IllegalArgumentException.class)
    public void creatingWithNullDelegateYieldsException() {
        new Reductor<Long, Integer>(null, 0l);
    }
   
    @Test(expected = IllegalArgumentException.class)
    public void consumingNullIteratorYieldException() {
        new Reductor<Long, Integer>(new Count<Integer>(), 0l).perform(null);
    }
   

    @Test(expected = ClassCastException.class)
    public void passingWrongTypeToErasureYieldsException() {
        Delegate c = new Reductor<Long, Integer>(new Count<Integer>(), 0l);
        c.perform(new Object());
    }   
}
TOP

Related Classes of net.emaze.dysfunctional.reductions.ReductorTest

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.