Skip to content
Permalink
Browse files
Converting to JUnit 4 and renaming test classes to make naming consis…
…tent (*Test as opposed to Test*).

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/proxy/branches/version-2.0-work@1510014 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jwcarman committed Aug 3, 2013
1 parent d0510d5 commit 718836c01c5314fbb14957520588b59d024042f5
Showing 23 changed files with 298 additions and 287 deletions.
@@ -19,13 +19,13 @@

import org.apache.commons.proxy2.AbstractSubclassingProxyFactoryTestCase;

public class TestCglibProxyFactory extends AbstractSubclassingProxyFactoryTestCase
public class CglibProxyFactoryTest extends AbstractSubclassingProxyFactoryTestCase
{
//**********************************************************************************************************************
// Constructors
//**********************************************************************************************************************

public TestCglibProxyFactory()
public CglibProxyFactoryTest()
{
}
}
@@ -17,13 +17,13 @@

package org.apache.commons.proxy2.provider;

import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.reflect.MethodUtils;
import org.apache.commons.proxy2.ObjectProvider;
import org.apache.commons.proxy2.ProxyUtils;
import org.apache.commons.proxy2.exception.ObjectProviderException;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
* Merely calls <code>clone()</code> (reflectively) on the given {@link Cloneable} object.
@@ -33,15 +33,16 @@
*/
public class CloningProvider<T extends Cloneable> implements ObjectProvider<T>, Serializable
{
/** Serialization version */
/**
* Serialization version
*/
private static final long serialVersionUID = 1L;

//**********************************************************************************************************************
// Fields
//**********************************************************************************************************************

private final T cloneable;
private Method cloneMethod;

//**********************************************************************************************************************
// Constructors
@@ -53,14 +54,18 @@
*
* @param cloneable the object to clone
*/
public CloningProvider( T cloneable )
public CloningProvider(T cloneable)
{
this.cloneable = cloneable;
Validate.isTrue(
MethodUtils.getAccessibleMethod(cloneable.getClass(), "clone") != null,
String.format("Class %s does not override clone() method as public.",
cloneable.getClass().getName()));
this.cloneable = Validate.notNull(cloneable, "Cloneable object cannot be null.");
}

//**********************************************************************************************************************
// ObjectProvider Implementation
//**********************************************************************************************************************
//**********************************************************************************************************************
// ObjectProvider Implementation
//**********************************************************************************************************************

/**
* {@inheritDoc}
@@ -70,38 +75,28 @@ public T getObject()
{
try
{
return (T)getCloneMethod().invoke(cloneable, ProxyUtils.EMPTY_ARGUMENTS);
return (T) MethodUtils.invokeExactMethod(cloneable, "clone");
}
catch( IllegalAccessException e )
catch (IllegalAccessException e)
{
throw new ObjectProviderException(
"Class " + cloneable.getClass().getName() + " does not have a public clone() method.", e);
}
catch( InvocationTargetException e )
catch (InvocationTargetException e)
{
throw new ObjectProviderException(
"Attempt to clone object of type " + cloneable.getClass().getName() + " threw an exception.", e);
}
catch (NoSuchMethodException e)
{
throw new ObjectProviderException(
String.format("Class %s does not have a clone() method (should never happen).", cloneable.getClass().getName()));
}
}

//**********************************************************************************************************************
// Getter/Setter Methods
//**********************************************************************************************************************

private synchronized Method getCloneMethod()
{
if( cloneMethod == null )
{
try
{
cloneMethod = cloneable.getClass().getMethod("clone", ProxyUtils.EMPTY_ARGUMENT_TYPES);
}
catch( NoSuchMethodException e )
{
throw new ObjectProviderException(
"Class " + cloneable.getClass().getName() + " does not have a public clone() method.", e);
}
}
return cloneMethod;
}

}

0 comments on commit 718836c

Please sign in to comment.