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.adapter;
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.Procedure;
026import org.apache.commons.functor.core.NoOp;
027import org.apache.commons.functor.core.RightIdentity;
028import org.junit.Test;
029
030/**
031 * @version $Revision: 1508677 $ $Date: 2013-07-31 00:48:02 +0200 (Mi, 31 Jul 2013) $
032 */
033public class TestLeftBoundProcedure extends BaseFunctorTest {
034
035    // Functor Testing Framework
036    // ------------------------------------------------------------------------
037
038    @Override
039    protected Object makeFunctor() {
040        return new LeftBoundProcedure<Object>(NoOp.INSTANCE,"xyzzy");
041    }
042
043    // Tests
044    // ------------------------------------------------------------------------
045
046    @Test
047    public void testRun() throws Exception {
048        Procedure<Object> p = new LeftBoundProcedure<Object>(
049                new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "foo");
050        p.run(Boolean.TRUE);
051        p.run(Boolean.FALSE);
052    }
053
054    @Test
055    public void testEquals() throws Exception {
056        Procedure<Object> f = new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy");
057        assertEquals(f, f);
058        assertObjectsAreEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, "xyzzy"));
059        assertObjectsAreNotEqual(f, new NoOp());
060        assertObjectsAreNotEqual(f, new LeftBoundProcedure<Object>(
061                new BinaryFunctionBinaryProcedure<Object, Object>(RightIdentity.FUNCTION), "xyzzy"));
062        assertObjectsAreNotEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, "foo"));
063        assertObjectsAreNotEqual(f, new LeftBoundProcedure<Object>(NoOp.INSTANCE, null));
064        assertObjectsAreEqual(new LeftBoundProcedure<Object>(NoOp.INSTANCE, null), new LeftBoundProcedure<Object>(NoOp.INSTANCE, null));
065        assertTrue(!f.equals(null));
066    }
067
068    @Test
069    public void testAdaptNull() throws Exception {
070        assertNull(LeftBoundProcedure.bind(null,"xyzzy"));
071    }
072
073    @Test
074    public void testAdapt() throws Exception {
075        assertNotNull(LeftBoundProcedure.bind(new NoOp(),"xyzzy"));
076        assertNotNull(LeftBoundProcedure.bind(new NoOp(),null));
077    }
078}