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.adapters;
027:
028: import junit.framework.TestCase;
029: import org.easymock.MockControl;
030: import org.jicarilla.container.Resolver;
031: import org.jicarilla.container.adapters.ResolverBasedKeyAwareAdapter;
032:
033: /**
034: *
035: *
036: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
037: * @version $Id: ResolverBasedAdapterTestCase.java,v 1.2 2004/03/23 15:59:54 lsimons Exp $
038: */
039: public class ResolverBasedAdapterTestCase extends TestCase {
040: MockControl resolverControl;
041: Resolver resolver;
042:
043: public void setUp() throws Exception {
044: super .setUp();
045: resolverControl = MockControl.createControl(Resolver.class);
046: resolver = (Resolver) resolverControl.getMock();
047: }
048:
049: public void testConstructor() {
050: assertNotNull(new ResolverBasedKeyAwareAdapter(resolver));
051: try {
052: new ResolverBasedKeyAwareAdapter(null);
053: fail("Expected an exception!");
054: } catch (AssertionError ae) {
055: }
056:
057: }
058:
059: public void testGetInstance() {
060: RuntimeException re = new RuntimeException();
061: resolver.get("blah");
062: resolverControl.setReturnValue(this );
063: resolver.get(null);
064: resolverControl.setThrowable(re);
065: resolverControl.replay();
066:
067: ResolverBasedKeyAwareAdapter adapter = new ResolverBasedKeyAwareAdapter(
068: resolver);
069:
070: assertEquals(this , adapter.getInstance("blah"));
071: try {
072: adapter.getInstance(null);
073: fail("Expected an exception!");
074: } catch (Throwable th) {
075: assertEquals(re, th);
076: }
077:
078: resolverControl.verify();
079: }
080:
081: public void testReleaseInstance() throws Exception {
082: Exception e = new Exception();
083: resolver.releaseInstance(this );
084: resolver.releaseInstance(null);
085: resolverControl.setThrowable(e);
086: resolverControl.replay();
087:
088: ResolverBasedKeyAwareAdapter adapter = new ResolverBasedKeyAwareAdapter(
089: resolver);
090:
091: adapter.releaseInstance(this );
092: try {
093: adapter.releaseInstance(null);
094: fail("Expected an exception!");
095: } catch (Throwable th) {
096: assertEquals(e, th);
097: }
098:
099: resolverControl.verify();
100: }
101: }
|