下面列出了怎么用org.apache.commons.lang3.exception.CloneFailedException的API类实例代码及写法,或者点击链接到github查看源代码。
private ExecutionConfig.SerializableSerializer<? extends Serializer<?>> deepCopySerializer(
ExecutionConfig.SerializableSerializer<? extends Serializer<?>> original) {
try {
return InstantiationUtil.clone(original, Thread.currentThread().getContextClassLoader());
} catch (IOException | ClassNotFoundException ex) {
throw new CloneFailedException(
"Could not clone serializer instance of class " + original.getClass(),
ex);
}
}
private ExecutionConfig.SerializableSerializer<? extends Serializer<?>> deepCopySerializer(
ExecutionConfig.SerializableSerializer<? extends Serializer<?>> original) {
try {
return InstantiationUtil.clone(original, Thread.currentThread().getContextClassLoader());
} catch (IOException | ClassNotFoundException ex) {
throw new CloneFailedException(
"Could not clone serializer instance of class " + original.getClass(),
ex);
}
}
/**
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
*/
public void testCloneOfUncloneable() {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.clone(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
}
}
/**
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
*/
public void testPossibleCloneOfUncloneable() {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.cloneIfPossible(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
assertEquals(NoSuchMethodException.class, e.getCause().getClass());
}
}
/**
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
*/
@Test(expected = NoSuchMethodException.class)
public void testCloneOfUncloneable() throws Throwable {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.clone(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
throw e.getCause();
}
}
/**
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
*/
@Test(expected = NoSuchMethodException.class)
public void testPossibleCloneOfUncloneable() throws Throwable {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.cloneIfPossible(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
throw e.getCause();
}
}
/**
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
*/
@Test(expected = NoSuchMethodException.class)
public void testCloneOfUncloneable() throws Throwable {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.clone(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
throw e.getCause();
}
}
/**
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
*/
@Test(expected = NoSuchMethodException.class)
public void testPossibleCloneOfUncloneable() throws Throwable {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.cloneIfPossible(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
throw e.getCause();
}
}
/**
* Tests {@link ObjectUtils#clone(Object)} with an uncloneable object.
*/
@Test(expected = NoSuchMethodException.class)
public void testCloneOfUncloneable() throws Throwable {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.clone(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
throw e.getCause();
}
}
/**
* Tests {@link ObjectUtils#cloneIfPossible(Object)} with an uncloneable object.
*/
@Test(expected = NoSuchMethodException.class)
public void testPossibleCloneOfUncloneable() throws Throwable {
final UncloneableString string = new UncloneableString("apache");
try {
ObjectUtils.cloneIfPossible(string);
fail("Thrown " + CloneFailedException.class.getName() + " expected");
} catch (final CloneFailedException e) {
throw e.getCause();
}
}
private ExecutionConfig.SerializableSerializer<? extends Serializer<?>> deepCopySerializer(
ExecutionConfig.SerializableSerializer<? extends Serializer<?>> original) {
try {
return InstantiationUtil.clone(original, Thread.currentThread().getContextClassLoader());
} catch (IOException | ClassNotFoundException ex) {
throw new CloneFailedException(
"Could not clone serializer instance of class " + original.getClass(),
ex);
}
}