krysalis-update/src/test/java/org/apache/depot/update/util/select/logic OrSelectorTests.java,NONE,1.1 AndSelectorTests.java,NONE,1.1 NotSelectorTests.java,NONE,1.1 BooleanSelectorTests.java,NONE,1.1

Nick Chalko <[email protected]> Wed, 08 Dec 2004 09:06:37 +0000
Newsgroups gmane.comp.krysalis.cvs
Message-ID <[email protected]>
Update of /cvsroot/krysalis/krysalis-update/src/test/java/org/apache/depot/update/util/select/logic
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24726/src/test/java/org/apache/depot/update/util/select/logic

Added Files:
	OrSelectorTests.java AndSelectorTests.java 
	NotSelectorTests.java BooleanSelectorTests.java 
Log Message:
Copied from the apache incubator.

--- NEW FILE: BooleanSelectorTests.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.depot.update.util.select.logic;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.depot.update.util.select.ISelector;

public class BooleanSelectorTests extends TestCase {

    protected void setUp() {
    }

    protected void tearDown() {
    }

    public void testSelect() throws Exception {
        ISelector selector = new BooleanSelector(true);
        assertTrue("Select is true", selector.select(this)) ;
        selector = new BooleanSelector(false);
        assertFalse("Select is false", selector.select(this)) ;
    }

    /**
     * Test that identity is defined by result not be object.
     */
    public void testIdentity(){
        ISelector firstTrue = BooleanSelector.TRUE;
        ISelector secondTrue = new BooleanSelector( true );

        assertTrue("Two true selectors should be equals", firstTrue.equals( secondTrue ));
        assertTrue("Two true selectors should be equals", secondTrue.equals( firstTrue ));

        assertFalse("True and false selectors should not be equals", firstTrue.equals( BooleanSelector.FALSE ));

        assertEquals("Hashcode should be the same", firstTrue.hashCode(), secondTrue.hashCode() );
        assertTrue("True and false hashcode should be different", firstTrue.hashCode() != BooleanSelector.FALSE.hashCode() );

    }

    public static Test suite() {
        return new TestSuite(BooleanSelectorTests.class);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}



--- NEW FILE: OrSelectorTests.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.depot.update.util.select.logic;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.depot.update.util.select.MockSelector;

public class OrSelectorTests extends TestCase {
    OrSelector m_or = new OrSelector();

    protected void setUp() {
    }

    protected void tearDown() {
    }

    public void testEmpty() throws Exception {
        assertTrue("Empty selector should be true", m_or.select(this));
    }

    public void testTrue() throws Exception {
        m_or.addSelector( BooleanSelector.TRUE );
        assertTrue("Or with true should return true", m_or.select( this ));

        m_or.addSelector( new MockSelector(true));
        m_or.addSelector( new MockSelector(true));
        assertTrue("Or with all trues should return true", m_or.select( this ));
    }

    public void testFalse() throws Exception {
        m_or.addSelector( BooleanSelector.FALSE);
        assertFalse("Or with false should return false", m_or.select( this ));

        m_or.addSelector( new MockSelector(false));
        m_or.addSelector( new MockSelector(false));
        assertFalse("Or with all false should return false", m_or.select( this ));
    }

    public void testTrueAndFalse() throws Exception {
        m_or.addSelector( BooleanSelector.FALSE );
        m_or.addSelector( BooleanSelector.TRUE );
        assertTrue("Or with one true should return true", m_or.select( this ));
        m_or.addSelector( new MockSelector(false));
        assertTrue("Or with one true should return true", m_or.select( this ));
    }


    public static Test suite() {
        return new TestSuite(OrSelectorTests.class);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}



--- NEW FILE: AndSelectorTests.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.depot.update.util.select.logic;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.depot.update.util.select.MockSelector;

public class AndSelectorTests extends TestCase {

    AndSelector m_and = new AndSelector();

    public void testEmpty() throws Exception {
        assertTrue("Empty selector should be true", m_and.select(this));
    }

    public void testTrue() throws Exception {
        m_and.addSelector( BooleanSelector.TRUE );
        assertTrue("And with true should return true", m_and.select( this ));

        m_and.addSelector( new MockSelector(true));
        m_and.addSelector( new MockSelector(true));
        assertTrue("And with all trues should return true", m_and.select( this ));
    }

    public void testFalse() throws Exception {
        m_and.addSelector( BooleanSelector.FALSE);
        assertFalse("And with false should return false", m_and.select( this ));

        m_and.addSelector( new MockSelector(false));
        m_and.addSelector( new MockSelector(false));
        assertFalse("And with all false should return false", m_and.select( this ));
    }

    public void testTrueAndFalse() throws Exception {
        m_and.addSelector( BooleanSelector.TRUE );
        m_and.addSelector( BooleanSelector.FALSE );
        assertFalse("And with one false should return false", m_and.select( this ));
        m_and.addSelector( new MockSelector(true));
        assertFalse("And with one false should return false", m_and.select( this ));
    }

    public static Test suite() {
        return new TestSuite(AndSelectorTests.class);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}



--- NEW FILE: NotSelectorTests.java ---
/*
 * Copyright  2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package org.apache.depot.update.util.select.logic;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

public class NotSelectorTests extends TestCase {

    private NotSelector m_not = new NotSelector();

    public void testEmpty() throws Exception {
        assertFalse("Not should be false when empty", m_not.select(this )) ;
    }

    public void testSetNull() {
        try{
            m_not.setSelector( null );
            fail("Should throw exception if we try to set null selector");
        } catch( IllegalArgumentException e ) {
            //expect this
        }
    }

    public void testNot() throws Exception {
        m_not.setSelector( BooleanSelector.TRUE );
        assertFalse("Not should be false when arg is true", m_not.select(this )) ;

        m_not.setSelector( BooleanSelector.FALSE );
        assertTrue("Not should be true when arg is false", m_not.select(this )) ;
    }

    public void testEquals() {
        NotSelector testSelector = new NotSelector( BooleanSelector.TRUE );
        m_not.setSelector( BooleanSelector.TRUE );

        assertTrue("Selectors should be equal", m_not.equals(testSelector));
        assertTrue("Selectors should be equal", testSelector.equals(m_not));

        m_not.setSelector( BooleanSelector.FALSE );
        assertFalse("Selectors should not be equal", m_not.equals(testSelector));
        assertFalse("Selectors should not be equal", testSelector.equals(m_not));
    }

    public void testHashCode() {
        NotSelector testSelector = new NotSelector( BooleanSelector.TRUE );
        m_not.setSelector( BooleanSelector.TRUE );

        assertEquals("Selectors should have same hashcode", m_not.hashCode(),
                                                          testSelector.hashCode() );

        m_not.setSelector( BooleanSelector.FALSE );
        assertTrue("Selectors should have different hash codes",
                              m_not.hashCode() != testSelector.hashCode() );
    }

    public static Test suite() {
        return new TestSuite(NotSelectorTests.class);
    }

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }
}





-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/