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