package net.emaze.dysfunctional.order;

import java.util.Comparator;
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
    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);
    }
}

@@ -62,16 +62,85 @@
 arator;%0A
+import net.emaze.dysfunctional.dispatching.delegates.BinaryDelegate;%0A
 import n
@@ -446,32 +446,325 @@
 %3E(null);%0A    %7D%0A%0A
+    @Test(expected = ClassCastException.class)%0A    public void callingErasureWithWrongTypeYieldsException() %7B%0A        Comparator%3CInteger%3E comp = new ComparableComparator%3CInteger%3E();%0A        BinaryDelegate d = new MakeOrder%3CInteger%3E(comp);%0A        d.perform(new Object(), new Object());%0A    %7D%0A%0A
     @Test%0A    pu

make order coverage