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.PickyHintedClassSelector;
029: import org.jicarilla.container.selectors.ClassSelector;
030: import org.jicarilla.container.selectors.HintedClassSelector;
031: import org.jicarilla.container.tck.components.type3.rich.HomerImpl;
032: import org.jicarilla.container.tck.components.interfaces.Homer;
033: import org.jicarilla.container.tck.components.interfaces.HotdogBuyer;
034: import org.jicarilla.lang.TrueSelector;
035:
036: import junit.framework.TestCase;
037:
038: /**
039: *
040: *
041: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
042: * @version $Id: PickyHintedClassSelectorTestCase.java,v 1.2 2004/03/23 13:37:54 lsimons Exp $
043: */
044: public class PickyHintedClassSelectorTestCase extends TestCase {
045: public void testSelect() {
046: PickyHintedClassSelector selector = new PickyHintedClassSelector(
047: HomerImpl.class, "blah");
048:
049: assertFalse(selector.select(null));
050: assertFalse(selector.select(this ));
051:
052: assertTrue(selector.select(Homer.class));
053: assertTrue(selector.select(HomerImpl.class));
054: assertTrue(selector.select(HotdogBuyer.class));
055:
056: assertTrue(selector.select(Homer.class.getName()));
057: assertTrue(selector.select(HomerImpl.class.getName()));
058: assertTrue(selector.select(HotdogBuyer.class.getName()));
059:
060: assertFalse(selector.select(Homer.class.getName() + "/"));
061: assertFalse(selector
062: .select(HomerImpl.class.getName() + "/Blah"));
063: assertFalse(selector.select(HotdogBuyer.class.getName()
064: + "/Bladibla"));
065: assertFalse(selector.select(HotdogBuyer.class.getName()
066: + "blah"));
067: assertFalse(selector.select(HotdogBuyer.class.getName()
068: + "|blah"));
069: assertTrue(selector.select(HotdogBuyer.class.getName()
070: + "/blah"));
071:
072: assertFalse(selector.select(Homer.class.getName() + "[]"));
073: assertFalse(selector.select(Homer.class.getName() + "|"));
074: assertFalse(selector.select("Homer"));
075: assertFalse(selector.select(new HomerImpl()));
076: }
077:
078: public void testConstructor() {
079: new PickyHintedClassSelector(HomerImpl.class, "");
080:
081: Throwable t = null;
082: try {
083: new PickyHintedClassSelector(HomerImpl.class, null);
084: } catch (AssertionError th) {
085: t = th;
086: }
087: assertNotNull(t);
088:
089: t = null;
090: try {
091: new PickyHintedClassSelector(null, "");
092: } catch (AssertionError th) {
093: t = th;
094: }
095: assertNotNull(t);
096: }
097:
098: public void testGetCriterion() {
099: PickyHintedClassSelector selector = new PickyHintedClassSelector(
100: this .getClass(), "");
101: assertEquals(this .getClass(), selector.getCriterion());
102: }
103:
104: PickyHintedClassSelector selector = new PickyHintedClassSelector(
105: PickyHintedClassSelector.class, "blah");
106: PickyHintedClassSelector selector2 = new PickyHintedClassSelector(
107: PickyHintedClassSelector.class, "blah");
108: PickyHintedClassSelector selector3 = new PickyHintedClassSelector(
109: this .getClass(), "Blah");
110: PickyHintedClassSelector selector4 = new PickyHintedClassSelector(
111: this .getClass(), "Blah");
112: HintedClassSelector selector5 = new HintedClassSelector(this
113: .getClass());
114:
115: TrueSelector ts = new TrueSelector();
116:
117: public void testEquals() {
118: assertTrue(selector.equals(selector));
119: assertTrue(selector.equals(selector2));
120: assertFalse(selector.equals(selector3));
121: assertFalse(selector.equals(selector4));
122: assertFalse(selector.equals(selector5));
123: assertFalse(selector.equals(null));
124: assertFalse(selector.equals(this ));
125: assertFalse(selector.equals(ts));
126:
127: assertFalse(selector3.equals(selector));
128: assertFalse(selector3.equals(selector2));
129: assertTrue(selector3.equals(selector3));
130: assertTrue(selector3.equals(selector4));
131: assertFalse(selector3.equals(selector5));
132: assertFalse(selector3.equals(null));
133: assertFalse(selector3.equals(this ));
134: assertFalse(selector3.equals(ts));
135:
136: assertFalse(selector5.equals(selector));
137: assertFalse(selector5.equals(selector2));
138: assertFalse(selector5.equals(selector3));
139: assertFalse(selector5.equals(selector4));
140: assertFalse(selector5.equals(null));
141: assertFalse(selector5.equals(this ));
142: assertFalse(selector5.equals(ts));
143: }
144:
145: public void testHashCode() {
146: assertEquals(selector.hashCode(), selector.hashCode());
147: assertEquals(selector.hashCode(), selector2.hashCode());
148: assertEquals(selector3.hashCode(), selector3.hashCode());
149: assertEquals(selector4.hashCode(), selector4.hashCode());
150: assertEquals(selector5.hashCode(), selector5.hashCode());
151:
152: assertFalse(selector.hashCode() == selector3.hashCode());
153: assertFalse(selector.hashCode() == selector4.hashCode());
154: assertFalse(selector.hashCode() == selector5.hashCode());
155: assertFalse(selector.hashCode() == -1);
156: assertFalse(selector.hashCode() == this .hashCode());
157: assertFalse(selector.hashCode() == ts.hashCode());
158:
159: assertFalse(selector3.hashCode() == selector.hashCode());
160: assertFalse(selector3.hashCode() == selector2.hashCode());
161: assertFalse(selector3.hashCode() == selector5.hashCode());
162: assertFalse(selector3.hashCode() == -1);
163: assertFalse(selector3.hashCode() == this .hashCode());
164: assertFalse(selector3.hashCode() == ts.hashCode());
165:
166: assertFalse(selector5.hashCode() == selector.hashCode());
167: assertFalse(selector5.hashCode() == selector2.hashCode());
168: assertFalse(selector5.hashCode() == selector3.hashCode());
169: assertFalse(selector5.hashCode() == selector4.hashCode());
170: assertFalse(selector5.hashCode() == -1);
171: assertFalse(selector5.hashCode() == this.hashCode());
172: assertFalse(selector5.hashCode() == ts.hashCode());
173: }
174: }
|