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.tck.test.util;
027:
028: import junit.framework.TestCase;
029: import org.jicarilla.container.tck.util.DefaultProxyManager;
030: import org.jicarilla.container.tck.util.InvocationRecorderWrapperManager;
031: import org.jicarilla.container.tck.util.ProxyManager;
032: import org.jicarilla.container.tck.util.WrapperManager;
033:
034: /**
035: *
036: *
037: * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
038: * @version $Id: InvocationLoggerWrapperManagerTestCase.java,v 1.3 2004/01/18 19:32:05 lsimons Exp $
039: */
040: public class InvocationLoggerWrapperManagerTestCase extends TestCase {
041: public DefaultProxyManager pm = new DefaultProxyManager();
042: public InvocationRecorderWrapperManager m = new InvocationRecorderWrapperManager(
043: pm);
044: public MockImpl mock = new MockImpl();
045:
046: public void testConstructor() {
047: new InvocationRecorderWrapperManager(pm);
048: try {
049: new InvocationRecorderWrapperManager(null);
050:
051: fail("Expected an exception!");
052: } catch (AssertionError th) {
053: }
054: }
055:
056: public void testGetAllInterfaces() {
057: Exposer m = new Exposer(pm);
058: assertEquals(1, m.getAllInterfaces(mock).length);
059: assertEquals(Mock.class, m.getAllInterfaces(mock)[0]);
060: }
061:
062: public void testGetClassLoader() {
063: Exposer m = new Exposer(pm);
064: assertEquals(Thread.currentThread().getContextClassLoader(), m
065: .getClassLoader());
066: }
067:
068: public void testWrapWithLogger() {
069: WrapperManager.Entry e = m.wrapWithLogger(mock);
070:
071: assertNotNull(e.logger);
072: assertNotNull(e.target);
073: assertNotNull(e.proxy);
074: assertEquals(mock, e.target);
075: assertFalse(e.target.equals(e.proxy));
076: assertTrue(e.proxy instanceof Mock);
077:
078: try {
079: m.wrapWithLogger(null);
080: fail("Expected an exception!");
081: } catch (AssertionError th) {
082: }
083: }
084:
085: public static class Exposer extends
086: InvocationRecorderWrapperManager {
087: public Exposer(ProxyManager proxyManager) {
088: super (proxyManager);
089: }
090:
091: public Class[] getAllInterfaces(Object target) {
092: return super .getAllInterfaces(target);
093: }
094:
095: protected ClassLoader getClassLoader() {
096: return super .getClassLoader();
097: }
098: }
099:
100: public static interface Mock {
101: public void doStuff();
102:
103: public boolean getStuffDone();
104: }
105:
106: public static class MockImpl implements Mock {
107: public boolean m_stuffDone = false;
108:
109: public void doStuff() {
110: m_stuffDone = true;
111: }
112:
113: public boolean getStuffDone() {
114: return m_stuffDone;
115: }
116: }
117:
118: }
|