001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.functor.core.composite;
018
019import static org.junit.Assert.assertEquals;
020import static org.junit.Assert.assertNotNull;
021import static org.junit.Assert.assertNull;
022import static org.junit.Assert.assertTrue;
023
024import org.apache.commons.functor.BaseFunctorTest;
025import org.apache.commons.functor.BinaryFunction;
026import org.apache.commons.functor.core.Constant;
027import org.apache.commons.functor.core.LeftIdentity;
028import org.apache.commons.functor.core.RightIdentity;
029import org.junit.Test;
030
031/**
032 * @version $Revision: 1365329 $ $Date: 2012-07-25 00:34:23 +0200 (Mi, 25 Jul 2012) $
033 */
034public class TestTransposedFunction extends BaseFunctorTest {
035
036    // Functor Testing Framework
037    // ------------------------------------------------------------------------
038
039    @Override
040    protected Object makeFunctor() {
041        return new TransposedFunction<Object, Object, Object>(LeftIdentity.FUNCTION);
042    }
043
044    // Tests
045    // ------------------------------------------------------------------------
046
047    @Test
048    public void testEvaluate() throws Exception {
049        BinaryFunction<Object, Object, Object> f = new TransposedFunction<Object, Object, Object>(LeftIdentity.FUNCTION);
050        assertEquals("xyzzy",f.evaluate(null,"xyzzy"));
051        assertNull(f.evaluate("xyzzy",null));
052    }
053
054    @Test
055    public void testEquals() throws Exception {
056        BinaryFunction<Object, Object, Object> f = new TransposedFunction<Object, Object, Object>(LeftIdentity.FUNCTION);
057        assertEquals(f,f);
058        assertObjectsAreEqual(f,new TransposedFunction<Object, Object, Object>(LeftIdentity.FUNCTION));
059        assertObjectsAreNotEqual(f,new TransposedFunction<Object, Object, Object>(RightIdentity.FUNCTION));
060        assertObjectsAreNotEqual(f,Constant.of("y"));
061        assertTrue(!f.equals((TransposedFunction<?, ?, ?>)null));
062    }
063
064    @Test
065    public void testTransposeNull() throws Exception {
066        assertNull(TransposedFunction.transpose(null));
067    }
068
069    @Test
070    public void testTranspose() throws Exception {
071        assertNotNull(TransposedFunction.transpose(Constant.of("x")));
072    }
073}