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 junit.framework.TestCase;
029: import org.jicarilla.lang.OrSelector;
030: import org.jicarilla.lang.Selector;
031: import org.jicarilla.lang.StringSelector;
032: import org.jicarilla.lang.TrueSelector;
033:
034: import java.util.Arrays;
035:
036: /**
037: *
038: *
039: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
040: * @version $Id: OrSelectorTestCase.java,v 1.1 2004/03/23 13:37:58 lsimons Exp $
041: */
042: public class OrSelectorTestCase extends TestCase {
043: StringSelector stringSelector1 = new StringSelector("blah");
044: StringSelector stringSelector2 = new StringSelector("blahblah");
045: StringSelector stringSelector3 = new StringSelector("");
046: StringSelector stringSelector4 = new StringSelector("");
047: StringSelector stringSelector5 = new StringSelector("blah");
048: StringSelector stringSelector6 = new StringSelector("blah");
049: StringSelector stringSelector7 = new StringSelector("blah", true);
050: StringSelector stringSelector75 = new StringSelector("blah", true);
051: StringSelector stringSelector8 = new StringSelector("Blah", true);
052: StringSelector stringSelector9 = new StringSelector("bah", true);
053:
054: TrueSelector ts = new TrueSelector();
055:
056: OrSelector selector = new OrSelector(new Selector[] {
057: stringSelector1, stringSelector2 });
058: OrSelector selector2 = new OrSelector(new Selector[] {
059: stringSelector1, stringSelector2 });
060: OrSelector selector3 = new OrSelector(new Selector[] {
061: stringSelector1, stringSelector2, null });
062: OrSelector selector4 = new OrSelector(new Selector[] {
063: stringSelector1, stringSelector2, null });
064: OrSelector selector5 = new OrSelector(new Selector[0]);
065:
066: public void testSelect() {
067: assertTrue(selector.select("blah"));
068: assertTrue(selector.select("blahblah"));
069: assertFalse(selector.select("Blah"));
070: assertFalse(selector.select(null));
071: assertFalse(selector.select(this ));
072:
073: selector = new OrSelector(new Selector[0]);
074:
075: assertFalse(selector.select("blah"));
076: assertFalse(selector.select("blahblah"));
077: assertFalse(selector.select("Blah"));
078: assertFalse(selector.select(null));
079: assertFalse(selector.select(this ));
080:
081: AssertionError ae = null;
082: try {
083: new OrSelector(null);
084: } catch (AssertionError e) {
085: ae = e;
086: }
087: assertNotNull(ae);
088:
089: }
090:
091: public void testGetCriterion() {
092: assertTrue(Arrays.equals(new Selector[] { stringSelector1,
093: stringSelector2 }, (Object[]) selector.getCriterion()));
094: }
095:
096: public void testEquals() {
097: assertTrue(selector.equals(selector));
098: assertTrue(selector.equals(selector2));
099: assertFalse(selector.equals(selector3));
100: assertFalse(selector.equals(selector5));
101: assertFalse(selector.equals(null));
102: assertFalse(selector.equals(this ));
103: assertFalse(selector.equals(ts));
104:
105: assertTrue(selector2.equals(selector2));
106: assertTrue(selector2.equals(selector));
107:
108: assertTrue(selector3.equals(selector3));
109: assertTrue(selector3.equals(selector4));
110: assertFalse(selector3.equals(selector));
111: assertFalse(selector3.equals(selector2));
112: assertFalse(selector3.equals(selector5));
113: assertFalse(selector3.equals(null));
114: assertFalse(selector3.equals(this ));
115: assertFalse(selector3.equals(ts));
116:
117: assertTrue(selector5.equals(selector5));
118: assertFalse(selector5.equals(selector));
119: assertFalse(selector5.equals(selector2));
120: assertFalse(selector5.equals(selector3));
121: assertFalse(selector5.equals(null));
122: assertFalse(selector5.equals(this ));
123: assertFalse(selector5.equals(ts));
124: }
125:
126: public void testHashCode() {
127: assertEquals(selector.hashCode(), selector.hashCode());
128: assertEquals(selector.hashCode(), selector2.hashCode());
129: assertEquals(selector3.hashCode(), selector3.hashCode());
130: assertEquals(selector4.hashCode(), selector4.hashCode());
131: assertEquals(selector5.hashCode(), selector5.hashCode());
132: assertEquals(selector3.hashCode(), selector4.hashCode());
133:
134: assertFalse(selector.hashCode() == selector3.hashCode());
135: assertFalse(selector.hashCode() == selector4.hashCode());
136: assertFalse(selector.hashCode() == selector5.hashCode());
137: assertFalse(selector.hashCode() == -1);
138: assertFalse(selector.hashCode() == this .hashCode());
139: assertFalse(selector.hashCode() == ts.hashCode());
140:
141: assertFalse(selector3.hashCode() == selector.hashCode());
142: assertFalse(selector3.hashCode() == selector2.hashCode());
143: assertFalse(selector3.hashCode() == selector5.hashCode());
144: assertFalse(selector3.hashCode() == -1);
145: assertFalse(selector3.hashCode() == this .hashCode());
146: assertFalse(selector3.hashCode() == ts.hashCode());
147:
148: assertFalse(selector5.hashCode() == selector.hashCode());
149: assertFalse(selector5.hashCode() == selector2.hashCode());
150: assertFalse(selector5.hashCode() == selector3.hashCode());
151: assertFalse(selector5.hashCode() == selector4.hashCode());
152: assertFalse(selector5.hashCode() == -1);
153: assertFalse(selector5.hashCode() == this.hashCode());
154: assertFalse(selector5.hashCode() == ts.hashCode());
155: }
156: }
|