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