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