org.callbackparams.support.ExceptionUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of callbackparams Show documentation
Show all versions of callbackparams Show documentation
CallbackParams is a JUnit-extension for writing parameterized tests.
It unlocks new innovative patterns that offer elegant solutions to many
obstacles that are traditionally associated with parameterized testing.
The newest version!
/*
* Copyright 2011 the original author or authors.
*
* 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.callbackparams.support;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* @author Henrik Kaipe
*/
public class ExceptionUtil {
public static Error unchecked(Throwable t) {
if (t instanceof RuntimeException) {
throw (RuntimeException)t;
} else if (t instanceof Error) {
throw (Error)t;
} else if (t instanceof InvocationTargetException) {
Set/*InvocationTargetException*/ targetTrace = new HashSet();
while (targetTrace.add(t)) {
t = ((InvocationTargetException)t).getTargetException();
if (false == t instanceof InvocationTargetException) {
throw unchecked(t);
}
}
}
Error e = new Error(t);
StackTraceElement[] stackTrace = e.getStackTrace();
int subListStart = 1;
e.setStackTrace((StackTraceElement[])
Arrays.asList(stackTrace).subList(subListStart, stackTrace.length)
.toArray(new StackTraceElement[stackTrace.length - subListStart]));
throw e;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy