Skip to content

Commit

Permalink
Converting to JUnit 4 and renaming test classes to make naming consis…
Browse files Browse the repository at this point in the history
…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 718836c
Show file tree
Hide file tree
Showing 23 changed files with 298 additions and 287 deletions.
Expand Up @@ -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()
{
}
}
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -53,14 +54,18 @@ public class CloningProvider<T extends Cloneable> implements ObjectProvider<T>,
*
* @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}
Expand All @@ -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.