Package net.emaze.dysfunctional.numbers

Source Code of net.emaze.dysfunctional.numbers.IsEvenTest

package net.emaze.dysfunctional.numbers;

import net.emaze.dysfunctional.dispatching.logic.Predicate;
import net.emaze.dysfunctional.numbers.policies.ModulusPolicy;
import net.emaze.dysfunctional.testing.O;
import org.junit.Assert;
import org.junit.Test;

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

    @Test(expected = IllegalArgumentException.class)
    public void creatingWithNullPolicyYieldsException() {
        new IsEven<O, O>(null, O.ONE);
    }

    @Test
    public void isEvenWhenModulusIsEqualToZero() {
        final O zero = O.ONE;
        final Predicate<O> even = new IsEven<O, O>(new ModulusPolicy<O, O, Integer>() {

            @Override
            public O modulus(O lhs, Integer modulus) {
                return O.ONE;
            }
        }, zero);

        Assert.assertTrue(even.accept(O.ONE));
    }

    @Test
    public void isNotEvenWhenModulusIsNotEqualToZero() {
        final O zero = O.ONE;
        final Predicate<O> even = new IsEven<O, O>(new ModulusPolicy<O, O, Integer>() {

            @Override
            public O modulus(O lhs, Integer modulus) {
                return O.ANOTHER;
            }
        }, zero);

        Assert.assertFalse(even.accept(O.ONE));
    }
}
TOP

Related Classes of net.emaze.dysfunctional.numbers.IsEvenTest

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.