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.builder;
027:
028: import junit.framework.TestCase;
029: import org.easymock.MockControl;
030: import org.jicarilla.container.KeyAwareAdapter;
031: import org.jicarilla.container.Resolver;
032: import org.jicarilla.container.builder.ResolverHelper;
033: import org.jicarilla.lang.Selector;
034:
035: /**
036: *
037: *
038: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
039: * @version $Id: ResolverHelperTestCase.java,v 1.3 2004/03/23 15:59:55 lsimons Exp $
040: */
041: public class ResolverHelperTestCase extends TestCase {
042: MockControl resolverControl;
043: Resolver resolver;
044:
045: public void setUp() throws Exception {
046: super .setUp();
047: resolverControl = MockControl.createControl(Resolver.class);
048: resolver = (Resolver) resolverControl.getMock();
049: }
050:
051: public void testGetAdapter() throws Exception {
052: String value = "booh!";
053: resolver.get("blah");
054: resolverControl.setReturnValue(value);
055: resolverControl.replay();
056:
057: ResolverHelper h = new ResolverHelper();
058:
059: KeyAwareAdapter a = h.getAdapter(resolver);
060: assertEquals(value, a.getInstance("blah"));
061:
062: resolverControl.verify();
063: }
064:
065: public void testGetAdapterDoesNotAcceptNullArgument()
066: throws Exception {
067: ResolverHelper helper = new ResolverHelper();
068: try {
069: helper.getAdapter(null);
070: fail("Expected an exception!");
071: } catch (AssertionError e) {
072: }
073: }
074:
075: public void testGetAdapterThrowsClassCastException()
076: throws Exception {
077: ResolverHelper helper = new ResolverHelper();
078: try {
079: helper.getAdapter(this );
080: fail("Expected an exception!");
081: } catch (ClassCastException e) {
082: }
083: }
084:
085: public void testGetSelector() throws Exception {
086: resolver.contains("blah");
087: resolverControl.setReturnValue(true);
088: resolverControl.replay();
089:
090: ResolverHelper h = new ResolverHelper();
091: Selector s = h.getSelector(resolver);
092: assertTrue(s.select("blah"));
093:
094: resolverControl.verify();
095: }
096:
097: public void testGetSelectorDoesNotAcceptNullArgument()
098: throws Exception {
099: ResolverHelper helper = new ResolverHelper();
100: try {
101: helper.getSelector(null);
102: fail("Expected an exception!");
103: } catch (AssertionError e) {
104: }
105: }
106:
107: public void testGetSelectorThrowsClassCastException()
108: throws Exception {
109: ResolverHelper helper = new ResolverHelper();
110: try {
111: helper.getSelector(this );
112: fail("Expected an exception!");
113: } catch (ClassCastException e) {
114: }
115: }
116: }
|