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