Package net.emaze.dysfunctional.order

Source Code of net.emaze.dysfunctional.order.MakeOrderTest

package net.emaze.dysfunctional.order;

import java.util.Comparator;
import net.emaze.dysfunctional.dispatching.delegates.BinaryDelegate;
import net.emaze.dysfunctional.tuples.Pair;
import org.junit.Assert;
import org.junit.Test;

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

    @Test(expected = IllegalArgumentException.class)
    public void creatingMakeOrderWithNullComparatorYieldsException() {
        new MakeOrder<Object>(null);
    }

    @Test(expected = ClassCastException.class)
    public void callingErasureWithWrongTypeYieldsException() {
        Comparator<Integer> comp = new ComparableComparator<Integer>();
        BinaryDelegate d = new MakeOrder<Integer>(comp);
        d.perform(new Object(), new Object());
    }

    @Test
    public void canOrderComparablesWhenLhsIsLesser() {
        Comparator<Integer> comp = new ComparableComparator<Integer>();
        Pair<Integer, Integer> got = new MakeOrder<Integer>(comp).perform(1, 2);
        Assert.assertEquals(Pair.of(1, 2), got);
    }

    @Test
    public void canOrderComparablesWhenLhsIsGreater() {
        Comparator<Integer> comp = new ComparableComparator<Integer>();
        Pair<Integer, Integer> got = new MakeOrder<Integer>(comp).perform(2, 1);
        Assert.assertEquals(Pair.of(1, 2), got);
    }

    @Test
    public void canOrderComparablesWhenLhsIsSameOrderAsRhs() {
        Comparator<Integer> comp = new ComparableComparator<Integer>();
        Pair<Integer, Integer> got = new MakeOrder<Integer>(comp).perform(1, 1);
        Assert.assertEquals(Pair.of(1, 1), got);
    }
}
TOP

Related Classes of net.emaze.dysfunctional.order.MakeOrderTest

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.