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