001: /* ====================================================================
002: The Jicarilla Software License
003:
004: Copyright (c) 2003 Leo Simons.
005: All rights reserved.
006:
007: Permission is hereby granted, free of charge, to any person obtaining
008: a copy of this software and associated documentation files (the
009: "Software"), to deal in the Software without restriction, including
010: without limitation the rights to use, copy, modify, merge, publish,
011: distribute, sublicense, and/or sell copies of the Software, and to
012: permit persons to whom the Software is furnished to do so, subject to
013: the following conditions:
014:
015: The above copyright notice and this permission notice shall be
016: included in all copies or substantial portions of the Software.
017:
018: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
020: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
021: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
022: CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
023: TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
024: SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
025: ==================================================================== */
026: package org.jicarilla.lang.test;
027:
028: import org.jicarilla.lang.EquivalenceSelector;
029: import org.jicarilla.lang.FalseSelector;
030: import org.jicarilla.lang.TrueSelector;
031: import junit.framework.TestCase;
032:
033: /**
034: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
035: * @version $Id: EquivalenceSelectorTestCase.java,v 1.1 2004/03/23 13:37:58 lsimons Exp $
036: */
037: public class EquivalenceSelectorTestCase extends TestCase {
038: public void testSelect() {
039: EquivalenceSelector selector = new EquivalenceSelector("blah");
040:
041: assertTrue(selector.select("blah"));
042: assertFalse(selector.select("Blah"));
043: assertFalse(selector.select(null));
044: assertFalse(selector.select(this ));
045:
046: assertFalse(selector
047: .select(new RegexpSelectorTestCase.StringObj("blah")));
048:
049: assertFalse(selector
050: .select(new RegexpSelectorTestCase.StringObj("Blah")));
051:
052: AssertionError ae = null;
053: try {
054: new EquivalenceSelector(null);
055: } catch (AssertionError e) {
056: ae = e;
057: }
058: assertNull(ae);
059:
060: selector = new EquivalenceSelector(null);
061:
062: assertFalse(selector.select("blah"));
063: assertFalse(selector.select("Blah"));
064: assertTrue(selector.select(null));
065: assertFalse(selector.select(this ));
066:
067: }
068:
069: public void testGetCriterion() {
070: EquivalenceSelector selector = new EquivalenceSelector("blah");
071: assertEquals("blah", selector.getCriterion());
072:
073: selector = new EquivalenceSelector(this );
074: assertEquals(this , selector.getCriterion());
075:
076: selector = new EquivalenceSelector(null);
077: assertEquals(null, selector.getCriterion());
078: }
079:
080: public void testEquals() {
081: EquivalenceSelector selector = new EquivalenceSelector(null);
082: EquivalenceSelector selector2 = new EquivalenceSelector(null);
083: EquivalenceSelector selector3 = new EquivalenceSelector(this );
084: EquivalenceSelector selector4 = new EquivalenceSelector(
085: new Object());
086:
087: TrueSelector ts = new TrueSelector();
088:
089: assertTrue(selector.equals(selector));
090: assertTrue(selector.equals(selector2));
091: assertFalse(selector.equals(selector3));
092: assertFalse(selector.equals(selector4));
093: assertFalse(selector.equals(null));
094: assertFalse(selector.equals(this ));
095: assertFalse(selector.equals(ts));
096:
097: assertFalse(selector3.equals(selector));
098: assertFalse(selector3.equals(selector4));
099: assertFalse(selector3.equals(null));
100: assertFalse(selector.equals(this ));
101: }
102:
103: public void testHashCode() {
104: EquivalenceSelector selector = new EquivalenceSelector(null);
105: EquivalenceSelector selector2 = new EquivalenceSelector(null);
106: EquivalenceSelector selector3 = new EquivalenceSelector(this );
107: EquivalenceSelector selector4 = new EquivalenceSelector(
108: new Object());
109:
110: assertEquals(selector.hashCode(), selector.hashCode());
111: assertEquals(selector.hashCode(), selector2.hashCode());
112: assertFalse(selector.hashCode() == selector3.hashCode());
113: assertFalse(selector.hashCode() == selector4.hashCode());
114:
115: assertEquals(selector3.hashCode(), selector3.hashCode());
116: assertFalse(selector3.hashCode() == selector.hashCode());
117: }
118: }
|