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.ResolverSelector;
029: import org.jicarilla.container.selectors.ClassSelector;
030: import org.jicarilla.container.Resolver;
031: import org.jicarilla.container.ResolutionException;
032: import org.jicarilla.container.JicarillaIllegalAccessException;
033: import org.jicarilla.container.JicarillaInvocationTargetException;
034: import org.jicarilla.container.JicarillaInstantiationException;
035: import org.jicarilla.container.JicarillaClassNotFoundException;
036: import org.jicarilla.container.InitializationException;
037: import org.jicarilla.container.JicarillaException;
038: import org.jicarilla.container.tck.components.interfaces.Homer;
039: import org.jicarilla.container.tck.components.interfaces.HotdogBuyer;
040: import org.jicarilla.container.tck.components.type3.HomerImpl;
041: import org.jicarilla.lang.TrueSelector;
042: import org.easymock.MockControl;
043:
044: import junit.framework.TestCase;
045:
046: /**
047: *
048: *
049: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
050: * @version $Id: ResolverSelectorTestCase.java,v 1.2 2004/03/23 13:37:54 lsimons Exp $
051: */
052: public class ResolverSelectorTestCase extends TestCase {
053: MockControl resolverControl;
054: Resolver resolver;
055:
056: MockControl resolver2Control;
057: Resolver resolver2;
058:
059: ResolverSelector selector;
060: ResolverSelector selector2;
061: ResolverSelector selector3;
062: ResolverSelector selector4;
063:
064: TrueSelector ts = new TrueSelector();
065:
066: public static class MockResolver implements Resolver {
067: public Object get(Object key) throws ResolutionException,
068: JicarillaIllegalAccessException,
069: JicarillaInvocationTargetException,
070: JicarillaInstantiationException,
071: JicarillaClassNotFoundException,
072: InitializationException, JicarillaException {
073: return null;
074: }
075:
076: public Object[] getAll(Object key)
077: throws JicarillaIllegalAccessException,
078: JicarillaInvocationTargetException,
079: JicarillaInstantiationException,
080: JicarillaClassNotFoundException,
081: InitializationException, JicarillaException {
082: return new Object[0];
083: }
084:
085: public boolean contains(Object key) {
086: return false;
087: }
088:
089: public void releaseInstance(Object instance) throws Exception {
090: }
091: }
092:
093: public void setUp() throws Exception {
094: super .setUp();
095: resolverControl = MockControl.createControl(Resolver.class);
096: resolver = (Resolver) resolverControl.getMock();
097:
098: resolver2Control = MockControl.createControl(Resolver.class);
099: resolver2 = (Resolver) resolver2Control.getMock();
100:
101: selector = new ResolverSelector(resolver);
102: selector2 = new ResolverSelector(resolver);
103: selector3 = new ResolverSelector(resolver2);
104: selector4 = new ResolverSelector(resolver2);
105: }
106:
107: public void testSelect() {
108: ResolverSelector selector = new ResolverSelector(resolver);
109:
110: resolver.contains(null);
111: resolverControl.setReturnValue(false);
112: resolver.contains(this );
113: resolverControl.setReturnValue(false);
114: resolver.contains(Homer.class);
115: resolverControl.setReturnValue(true);
116: resolverControl.replay();
117:
118: assertFalse(selector.select(null));
119: assertFalse(selector.select(this ));
120: assertTrue(selector.select(Homer.class));
121:
122: resolverControl.verify();
123:
124: }
125:
126: public void testGetCriterion() {
127: ResolverSelector selector = new ResolverSelector(resolver);
128: assertEquals(resolver, selector.getCriterion());
129: }
130:
131: public void testExceptions() {
132: Throwable t = null;
133: try {
134: new ResolverSelector(null);
135: } catch (AssertionError th) {
136: t = th;
137: }
138: assertNotNull(t);
139: }
140:
141: public void testEquals() {
142: resolver = new MockResolver();
143: resolver2 = new MockResolver();
144:
145: selector = new ResolverSelector(resolver);
146: selector2 = new ResolverSelector(resolver);
147: selector3 = new ResolverSelector(resolver2);
148: selector4 = new ResolverSelector(resolver2);
149:
150: assertTrue(selector.equals(selector));
151: assertTrue(selector.equals(selector2));
152: assertFalse(selector.equals(selector3));
153: assertFalse(selector.equals(selector4));
154: assertFalse(selector.equals(null));
155: assertFalse(selector.equals(this ));
156: assertFalse(selector.equals(ts));
157:
158: assertFalse(selector3.equals(selector));
159: assertFalse(selector3.equals(selector2));
160: assertTrue(selector3.equals(selector3));
161: assertTrue(selector3.equals(selector4));
162: assertFalse(selector3.equals(null));
163: assertFalse(selector3.equals(this ));
164: assertFalse(selector3.equals(ts));
165: }
166:
167: public void testHashCode() {
168: resolver = new MockResolver();
169: resolver2 = new MockResolver();
170:
171: selector = new ResolverSelector(resolver);
172: selector2 = new ResolverSelector(resolver);
173: selector3 = new ResolverSelector(resolver2);
174: selector4 = new ResolverSelector(resolver2);
175:
176: assertEquals(selector.hashCode(), selector.hashCode());
177: assertEquals(selector.hashCode(), selector2.hashCode());
178: assertEquals(selector3.hashCode(), selector3.hashCode());
179: assertEquals(selector4.hashCode(), selector4.hashCode());
180:
181: assertFalse(selector.hashCode() == selector3.hashCode());
182: assertFalse(selector.hashCode() == selector4.hashCode());
183: assertFalse(selector.hashCode() == -1);
184: assertFalse(selector.hashCode() == this .hashCode());
185: assertFalse(selector.hashCode() == ts.hashCode());
186:
187: assertFalse(selector3.hashCode() == selector.hashCode());
188: assertFalse(selector3.hashCode() == selector2.hashCode());
189: assertFalse(selector3.hashCode() == -1);
190: assertFalse(selector3.hashCode() == this.hashCode());
191: assertFalse(selector3.hashCode() == ts.hashCode());
192: }
193: }
|