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.assertFalse; 021import static org.junit.Assert.assertNotNull; 022import static org.junit.Assert.assertNull; 023import static org.junit.Assert.assertTrue; 024 025import org.apache.commons.functor.BaseFunctorTest; 026import org.apache.commons.functor.Predicate; 027import org.apache.commons.functor.core.Constant; 028import org.apache.commons.functor.core.IsNotSame; 029import org.apache.commons.functor.core.IsSame; 030import org.junit.Test; 031 032/** 033 * @version $Revision: 1345136 $ $Date: 2012-06-01 09:47:06 -0300 (Fri, 01 Jun 2012) $ 034 */ 035public class TestBinaryPredicatePredicate extends BaseFunctorTest { 036 037 // Functor Testing Framework 038 // ------------------------------------------------------------------------ 039 040 @Override 041 protected Object makeFunctor() { 042 return new BinaryPredicatePredicate<Object>(IsSame.INSTANCE); 043 } 044 045 // Tests 046 // ------------------------------------------------------------------------ 047 048 @Test 049 public void testTestWhenTrue() throws Exception { 050 Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsSame.INSTANCE); 051 assertTrue(p.test(null)); 052 } 053 054 @Test 055 public void testTestWhenFalse() throws Exception { 056 Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsNotSame.INSTANCE); 057 assertFalse(p.test(null)); 058 } 059 060 @Test 061 public void testEquals() throws Exception { 062 Predicate<Object> p = new BinaryPredicatePredicate<Object>(IsSame.INSTANCE); 063 assertEquals(p, p); 064 assertObjectsAreEqual(p, new BinaryPredicatePredicate<Object>(IsSame.INSTANCE)); 065 assertObjectsAreNotEqual(p, Constant.truePredicate()); 066 assertObjectsAreNotEqual(p, new BinaryPredicatePredicate<Object>(IsNotSame.INSTANCE)); 067 } 068 069 @Test 070 public void testAdaptNull() throws Exception { 071 assertNull(BinaryPredicatePredicate.adapt(null)); 072 } 073 074 @Test 075 public void testAdapt() throws Exception { 076 assertNotNull(BinaryPredicatePredicate.adapt(Constant.TRUE)); 077 } 078}