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