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.AndSelector;
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: AndSelectorTestCase.java,v 1.1 2004/03/23 13:37:58 lsimons Exp $
041: */
042: public class AndSelectorTestCase 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: AndSelector selector = new AndSelector(new Selector[] {
057: stringSelector1, stringSelector5 });
058: AndSelector selector2 = new AndSelector(new Selector[] {
059: stringSelector1, stringSelector5 });
060: AndSelector selector3 = new AndSelector(new Selector[] {
061: stringSelector1, stringSelector5, null });
062: AndSelector selector4 = new AndSelector(new Selector[] {
063: stringSelector1, stringSelector5, null });
064: AndSelector selector5 = new AndSelector(new Selector[0]);
065:
066: public void testSelect() {
067: assertTrue(selector.select("blah"));
068: assertFalse(selector.select("blahblah"));
069: assertFalse(selector.select("Blah"));
070: assertFalse(selector.select(null));
071: assertFalse(selector.select(this ));
072:
073: selector = new AndSelector(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 AndSelector(null);
084: } catch (AssertionError e) {
085: ae = e;
086: }
087: assertNotNull(ae);
088: }
089:
090: public void testGetCriterion() {
091: assertTrue(Arrays.equals(new Selector[] { stringSelector1,
092: stringSelector5 }, (Object[]) selector.getCriterion()));
093: }
094:
095: public void testEquals() {
096: assertTrue(selector.equals(selector));
097: assertTrue(selector.equals(selector2));
098: assertFalse(selector.equals(selector3));
099: assertFalse(selector.equals(selector5));
100: assertFalse(selector.equals(null));
101: assertFalse(selector.equals(this ));
102: assertFalse(selector.equals(ts));
103:
104: assertTrue(selector2.equals(selector2));
105: assertTrue(selector2.equals(selector));
106:
107: assertTrue(selector3.equals(selector3));
108: assertTrue(selector3.equals(selector4));
109: assertFalse(selector3.equals(selector));
110: assertFalse(selector3.equals(selector2));
111: assertFalse(selector3.equals(selector5));
112: assertFalse(selector3.equals(null));
113: assertFalse(selector3.equals(this ));
114: assertFalse(selector3.equals(ts));
115:
116: assertTrue(selector5.equals(selector5));
117: assertFalse(selector5.equals(selector));
118: assertFalse(selector5.equals(selector2));
119: assertFalse(selector5.equals(selector3));
120: assertFalse(selector5.equals(null));
121: assertFalse(selector5.equals(this ));
122: assertFalse(selector5.equals(ts));
123: }
124:
125: public void testHashCode() {
126: assertEquals(selector.hashCode(), selector.hashCode());
127: assertEquals(selector.hashCode(), selector2.hashCode());
128: assertEquals(selector3.hashCode(), selector3.hashCode());
129: assertEquals(selector4.hashCode(), selector4.hashCode());
130: assertEquals(selector5.hashCode(), selector5.hashCode());
131: assertEquals(selector3.hashCode(), selector4.hashCode());
132:
133: assertFalse(selector.hashCode() == selector3.hashCode());
134: assertFalse(selector.hashCode() == selector4.hashCode());
135: assertFalse(selector.hashCode() == selector5.hashCode());
136: assertFalse(selector.hashCode() == -1);
137: assertFalse(selector.hashCode() == this .hashCode());
138: assertFalse(selector.hashCode() == ts.hashCode());
139:
140: assertFalse(selector3.hashCode() == selector.hashCode());
141: assertFalse(selector3.hashCode() == selector2.hashCode());
142: assertFalse(selector3.hashCode() == selector5.hashCode());
143: assertFalse(selector3.hashCode() == -1);
144: assertFalse(selector3.hashCode() == this .hashCode());
145: assertFalse(selector3.hashCode() == ts.hashCode());
146:
147: assertFalse(selector5.hashCode() == selector.hashCode());
148: assertFalse(selector5.hashCode() == selector2.hashCode());
149: assertFalse(selector5.hashCode() == selector3.hashCode());
150: assertFalse(selector5.hashCode() == selector4.hashCode());
151: assertFalse(selector5.hashCode() == -1);
152: assertFalse(selector5.hashCode() == this.hashCode());
153: assertFalse(selector5.hashCode() == ts.hashCode());
154: }
155: }
|