Author: jcarman Date: Tue Aug 30 14:30:53 2005 New Revision: 264871 URL: http://svn.apache.org/viewcvs?rev=264871&view=rev Log: Improving test coverage.
Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java (with props) jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java (with props) jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java (with props) jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java (with props) jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java (with props) Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java?rev=264871&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java Tue Aug 30 14:30:53 2005 @@ -0,0 +1,65 @@ +/* $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.proxy.exception; + +import junit.framework.TestCase; + +/** + * @author James Carman + * @version 1.0 + */ +public abstract class AbstractExceptionClassTestCase extends TestCase +{ + private final Class<? extends Exception> exceptionClass; + + public AbstractExceptionClassTestCase( Class<? extends Exception> exceptionClass ) + { + this.exceptionClass = exceptionClass; + } + + public void testNoArgConstructor() throws Exception + { + Exception e = exceptionClass.getConstructor().newInstance(); + assertNull( e.getMessage() ); + assertNull( e.getCause() ); + } + + public void testMessageOnlyConstructor() throws Exception + { + final String message = "message"; + Exception e = exceptionClass.getConstructor( String.class ).newInstance( message ); + assertEquals( message, e.getMessage() ); + assertNull( e.getCause() ); + } + + public void testCauseOnlyConstructor() throws Exception + { + final Exception cause = new Exception(); + Exception e = exceptionClass.getConstructor( Throwable.class ).newInstance( cause ); + assertEquals( cause.toString(), e.getMessage() ); + assertEquals( cause, e.getCause() ); + } + + public void testMessageAndCauseConstructor() throws Exception + { + final Exception cause = new Exception(); + final String message = "message"; + Exception e = exceptionClass.getConstructor( String.class, Throwable.class ).newInstance( message, cause ); + assertEquals( message, e.getMessage() ); + assertEquals( cause, e.getCause() ); + } +} Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/AbstractExceptionClassTestCase.java ------------------------------------------------------------------------------ svn:keywords = Id Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java?rev=264871&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java Tue Aug 30 14:30:53 2005 @@ -0,0 +1,25 @@ +/* $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.proxy.exception; + +public class TestDelegateProviderException extends AbstractExceptionClassTestCase +{ + public TestDelegateProviderException() + { + super( DelegateProviderException.class ); + } +} \ No newline at end of file Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestDelegateProviderException.java ------------------------------------------------------------------------------ svn:keywords = Id Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java?rev=264871&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java Tue Aug 30 14:30:53 2005 @@ -0,0 +1,29 @@ +/* $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.proxy.exception; + +/** + * @author James Carman + * @version 1.0 + */ +public class TestProxyFactoryException extends AbstractExceptionClassTestCase +{ + public TestProxyFactoryException() + { + super( ProxyFactoryException.class ); + } +} Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestProxyFactoryException.java ------------------------------------------------------------------------------ svn:keywords = Id Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java?rev=264871&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java Tue Aug 30 14:30:53 2005 @@ -0,0 +1,57 @@ +/* $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.proxy.factory.reflect; +import junit.framework.TestCase; +import org.apache.commons.proxy.util.Echo; + +import java.lang.reflect.Method; + +public class TestAbstractInvocationHandler extends TestCase +{ + public void testCreateProxy() throws Exception + { + final TestingInvocationHandler handler = new TestingInvocationHandler(); + Echo echo = ( Echo )handler.createProxy( Echo.class ); + echo.echo(); + assertEquals( Echo.class.getMethod( "echo" ), handler.method ); + assertNull( handler.arguments ); + echo.echoBack( "hello" ); + assertEquals( Echo.class.getMethod( "echoBack", String.class ), handler.method ); + assertNotNull( handler.arguments ); + assertEquals( 1, handler.arguments.length ); + assertEquals( "hello", handler.arguments[0] ); + echo.echoBack( "hello", "world" ); + assertEquals( Echo.class.getMethod( "echoBack", String.class, String.class ), handler.method ); + assertNotNull( handler.arguments ); + assertEquals( 2, handler.arguments.length ); + assertEquals( "hello", handler.arguments[0] ); + assertEquals( "world", handler.arguments[1] ); + } + + private static class TestingInvocationHandler extends AbstractInvocationHandler + { + private Method method; + private Object[] arguments; + + public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable + { + this.method = method; + this.arguments = args; + return null; + } + } +} \ No newline at end of file Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestAbstractInvocationHandler.java ------------------------------------------------------------------------------ svn:keywords = Id Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java?rev=264871&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java Tue Aug 30 14:30:53 2005 @@ -0,0 +1,50 @@ +/* $Id$ + * + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.proxy.factory.reflect; +import junit.framework.TestCase; +import org.apache.commons.proxy.util.Echo; +import org.apache.commons.proxy.util.EchoImpl; + +public class TestDelegatingInvocationHandler extends TestCase +{ + public void testCreateProxy() + { + final DelegatingInvocationHandler invocationHandler = new DelegatingInvocationHandler() + { + protected Object getDelegate() + { + return new EchoImpl(); + } + }; + final Echo echo = ( Echo )invocationHandler.createProxy(); + assertEquals( "message", echo.echoBack( "message" ) ); + } + + public void testClassLoaderCreateProxy() + { + final DelegatingInvocationHandler invocationHandler = new DelegatingInvocationHandler() + { + protected Object getDelegate() + { + return new EchoImpl(); + } + }; + final Echo echo = ( Echo )invocationHandler.createProxy( Thread.currentThread().getContextClassLoader() ); + assertEquals( "message", echo.echoBack( "message" ) ); + } + +} \ No newline at end of file Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/reflect/TestDelegatingInvocationHandler.java ------------------------------------------------------------------------------ svn:keywords = Id --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]