Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Work in progress, still.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/proxy/branches/version-2.0-work@964999 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
21 changed files
with
811 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.apache.commons.proxy.cglib.CglibProxyFactory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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; | ||
|
||
import junit.framework.TestCase; | ||
import org.apache.commons.proxy.util.DuplicateEcho; | ||
import org.apache.commons.proxy.util.Echo; | ||
import org.apache.commons.proxy.util.EchoImpl; | ||
|
||
import java.io.Serializable; | ||
import java.util.Arrays; | ||
import java.util.Properties; | ||
|
||
public class TestProxyUtils extends TestCase | ||
{ | ||
//********************************************************************************************************************** | ||
// Fields | ||
//********************************************************************************************************************** | ||
|
||
private Properties prevProperties; | ||
|
||
//********************************************************************************************************************** | ||
// Other Methods | ||
//********************************************************************************************************************** | ||
|
||
protected void setUp() throws Exception | ||
{ | ||
prevProperties = System.getProperties(); | ||
System.setProperties(new Properties()); | ||
} | ||
|
||
protected void tearDown() throws Exception | ||
{ | ||
System.setProperties(prevProperties); | ||
} | ||
|
||
public void testNullValue() | ||
{ | ||
assertNullValue(null, String.class); | ||
assertNullValue(( char ) 0, Character.TYPE); | ||
assertNullValue(0, Integer.TYPE); | ||
assertNullValue(( long ) 0, Long.TYPE); | ||
assertNullValue(( short ) 0, Short.TYPE); | ||
assertNullValue(( double ) 0, Double.TYPE); | ||
assertNullValue(( float ) 0, Float.TYPE); | ||
assertNullValue(false, Boolean.TYPE); | ||
assertNullValue(( byte ) 0, Byte.TYPE); | ||
} | ||
|
||
private void assertNullValue( Object expected, Class type ) | ||
{ | ||
assertEquals(expected, ProxyUtils.nullValue(type)); | ||
} | ||
|
||
public void testCreateNullObject() throws Exception | ||
{ | ||
final Echo nullEcho = ( Echo ) ProxyUtils | ||
.createNullObject(new JavassistProxyFactory(), new Class[] {Echo.class}); | ||
assertNull(nullEcho.echoBack("hello")); | ||
assertNull(nullEcho.echoBack("hello", "world")); | ||
assertEquals(( int ) 0, nullEcho.echoBack(12345)); | ||
} | ||
|
||
public void testCreateNullObjectWithClassLoader() throws Exception | ||
{ | ||
final Echo nullEcho = ( Echo ) ProxyUtils.createNullObject(new JavassistProxyFactory(), | ||
Echo.class.getClassLoader(), | ||
new Class[] {Echo.class}); | ||
assertNull(nullEcho.echoBack("hello")); | ||
assertNull(nullEcho.echoBack("hello", "world")); | ||
assertEquals(( int ) 0, nullEcho.echoBack(12345)); | ||
} | ||
|
||
public void testGetAllInterfaces() | ||
{ | ||
assertNull(ProxyUtils.getAllInterfaces(null)); | ||
assertEquals(Arrays.asList(new Class[] {DuplicateEcho.class, Serializable.class, Echo.class}), | ||
Arrays.asList(ProxyUtils.getAllInterfaces(EchoImpl.class))); | ||
} | ||
|
||
public void testGetJavaClassName() throws Exception | ||
{ | ||
assertEquals("java.lang.Object[]", ProxyUtils.getJavaClassName(Object[].class)); | ||
assertEquals("java.lang.Object[][]", ProxyUtils.getJavaClassName(Object[][].class)); | ||
assertEquals("java.lang.String[][][]", ProxyUtils.getJavaClassName(String[][][].class)); | ||
assertEquals("int", ProxyUtils.getJavaClassName(Integer.TYPE)); | ||
assertEquals("float", ProxyUtils.getJavaClassName(Float.TYPE)); | ||
assertEquals("long", ProxyUtils.getJavaClassName(Long.TYPE)); | ||
assertEquals("double", ProxyUtils.getJavaClassName(Double.TYPE)); | ||
assertEquals("short", ProxyUtils.getJavaClassName(Short.TYPE)); | ||
assertEquals("byte", ProxyUtils.getJavaClassName(Byte.TYPE)); | ||
assertEquals("char", ProxyUtils.getJavaClassName(Character.TYPE)); | ||
assertEquals("boolean", ProxyUtils.getJavaClassName(Boolean.TYPE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* @since 1.0 | ||
*/ | ||
public abstract class AbstractExceptionClassTestCase extends TestCase | ||
{ | ||
//********************************************************************************************************************** | ||
// Fields | ||
//********************************************************************************************************************** | ||
|
||
private final Class exceptionClass; | ||
|
||
//********************************************************************************************************************** | ||
// Constructors | ||
//********************************************************************************************************************** | ||
|
||
public AbstractExceptionClassTestCase( Class exceptionClass ) | ||
{ | ||
this.exceptionClass = exceptionClass; | ||
} | ||
|
||
//********************************************************************************************************************** | ||
// Other Methods | ||
//********************************************************************************************************************** | ||
|
||
public void testCauseOnlyConstructor() throws Exception | ||
{ | ||
final Exception cause = new Exception(); | ||
Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {Throwable.class}).newInstance(new Object[] {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 = ( Exception ) exceptionClass.getConstructor(new Class[] {String.class, Throwable.class}).newInstance(new Object[] {message, cause}); | ||
assertEquals(message, e.getMessage()); | ||
assertEquals(cause, e.getCause()); | ||
} | ||
|
||
public void testMessageOnlyConstructor() throws Exception | ||
{ | ||
final String message = "message"; | ||
Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {String.class}).newInstance(new Object[] {message}); | ||
assertEquals(message, e.getMessage()); | ||
assertNull(e.getCause()); | ||
} | ||
|
||
public void testNoArgConstructor() throws Exception | ||
{ | ||
Exception e = ( Exception ) exceptionClass.getConstructor(new Class[] {}).newInstance(new Object[] {}); | ||
assertNull(e.getMessage()); | ||
assertNull(e.getCause()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
{ | ||
//********************************************************************************************************************** | ||
// Constructors | ||
//********************************************************************************************************************** | ||
|
||
public TestDelegateProviderException() | ||
{ | ||
super(ObjectProviderException.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 TestInvocationHandlerException extends AbstractExceptionClassTestCase | ||
{ | ||
//********************************************************************************************************************** | ||
// Constructors | ||
//********************************************************************************************************************** | ||
|
||
public TestInvocationHandlerException() | ||
{ | ||
super(InvokerException.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* @since 1.0 | ||
*/ | ||
public class TestProxyFactoryException extends AbstractExceptionClassTestCase | ||
{ | ||
//********************************************************************************************************************** | ||
// Constructors | ||
//********************************************************************************************************************** | ||
|
||
public TestProxyFactoryException() | ||
{ | ||
super(ProxyFactoryException.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.impl; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class TestMethodSignature extends TestCase | ||
{ | ||
//********************************************************************************************************************** | ||
// Other Methods | ||
//********************************************************************************************************************** | ||
|
||
public void testEquals() throws Exception | ||
{ | ||
final MethodSignature sig = new MethodSignature(Echo.class.getMethod("echoBack", new Class[] {String.class})); | ||
assertTrue(sig.equals(sig)); | ||
assertFalse(sig.equals("echoBack")); | ||
assertEquals(sig, new MethodSignature(Echo.class.getMethod("echoBack", new Class[] {String.class}))); | ||
assertEquals(sig, new MethodSignature(DuplicateEcho.class.getMethod("echoBack", new Class[] {String.class}))); | ||
assertFalse(sig.equals(new MethodSignature(Echo.class.getMethod("echoBack", new Class[] {String.class, String.class})))); | ||
assertFalse(sig.equals(new MethodSignature(Echo.class.getMethod("echo", new Class[] {})))); | ||
} | ||
} |
Oops, something went wrong.