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