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