本文整理了Java中java.lang.AssertionError.initCause()
方法的一些代码示例,展示了AssertionError.initCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AssertionError.initCause()
方法的具体详情如下:
包路径:java.lang.AssertionError
类名称:AssertionError
方法名:initCause
暂无
代码示例来源:origin: prestodb/presto
public static AssertionError assertionError(String message, Exception e) {
return (AssertionError) new AssertionError(message).initCause(e);
}
代码示例来源:origin: org.testng/testng
/**
* Fails a test with the given message and wrapping the original exception.
*
* @param message the assertion error message
* @param realCause the original exception
*/
static public void fail(String message, Throwable realCause) {
AssertionError ae = new AssertionError(message);
ae.initCause(realCause);
throw ae;
}
代码示例来源:origin: org.testng/testng
/**
* Fails a test with the given message and wrapping the original exception.
*
* @param message the assertion error message
* @param realCause the original exception
*/
public static void fail(String message, Throwable realCause) {
AssertionError ae = new AssertionError(message);
ae.initCause(realCause);
throw ae;
}
代码示例来源:origin: junit-team/junit4
/**
* Adds a Throwable to the table. Execution continues, but the test will fail at the end.
*/
public void addError(Throwable error) {
if (error == null) {
throw new NullPointerException("Error cannot be null");
}
if (error instanceof AssumptionViolatedException) {
AssertionError e = new AssertionError(error.getMessage());
e.initCause(error);
errors.add(e);
} else {
errors.add(error);
}
}
代码示例来源:origin: google/guava
/** Alternative to AssertionError(String, Throwable), which doesn't exist in Java 1.6 */
private static AssertionError newAssertionError(String message, Throwable cause) {
AssertionError e = new AssertionError(message);
e.initCause(cause);
return e;
}
}
代码示例来源:origin: google/guava
/** Alternative to AssertionError(String, Throwable), which doesn't exist in GWT 2.6.1. */
private static AssertionError newAssertionError(String message, Throwable cause) {
AssertionError e = new AssertionError(message);
e.initCause(cause);
return e;
}
代码示例来源:origin: ReactiveX/RxJava
if (!errors.isEmpty()) {
if (errors.size() == 1) {
ae.initCause(errors.get(0));
} else {
CompositeException ce = new CompositeException(errors);
ae.initCause(ce);
代码示例来源:origin: google/guava
AssertionError error =
new AssertionFailedError("Serialization failed on return value of " + factory);
error.initCause(e.getCause());
throw error;
} catch (AssertionFailedError e) {
new AssertionFailedError(
"Return value of " + factory + " reserialized to an unequal value");
error.initCause(e);
throw error;
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz) {
Throwable ex = list.get(index);
if (!clazz.isInstance(ex)) {
AssertionError err = new AssertionError(clazz + " expected but got " + list.get(index));
err.initCause(list.get(index));
throw err;
}
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertUndeliverable(List<Throwable> list, int index, Class<? extends Throwable> clazz) {
Throwable ex = list.get(index);
if (!(ex instanceof UndeliverableException)) {
AssertionError err = new AssertionError("Outer exception UndeliverableException expected but got " + list.get(index));
err.initCause(list.get(index));
throw err;
}
ex = ex.getCause();
if (!clazz.isInstance(ex)) {
AssertionError err = new AssertionError("Inner exception " + clazz + " expected but got " + list.get(index));
err.initCause(list.get(index));
throw err;
}
}
代码示例来源:origin: google/guava
/**
* Runs serialization test on the return values of the static methods.
*
* <p>Test fails if default value cannot be determined for a constructor or factory method
* parameter, or if the constructor or factory method throws exception.
*
* @return this tester
*/
public FactoryMethodReturnValueTester testSerializable() throws Exception {
for (Invokable<?, ?> factory : getFactoriesToTest()) {
Object instance = instantiate(factory);
if (instance != null) {
try {
SerializableTester.reserialize(instance);
} catch (RuntimeException e) {
AssertionError error =
new AssertionFailedError("Serialization failed on return value of " + factory);
error.initCause(e.getCause());
throw error;
}
}
}
return this;
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(List<Throwable> list, int index, Class<? extends Throwable> clazz, String message) {
Throwable ex = list.get(index);
if (!clazz.isInstance(ex)) {
AssertionError err = new AssertionError("Type " + clazz + " expected but got " + ex);
err.initCause(ex);
throw err;
}
if (!ObjectHelper.equals(message, ex.getMessage())) {
AssertionError err = new AssertionError("Message " + message + " expected but got " + ex.getMessage());
err.initCause(ex);
throw err;
}
}
代码示例来源:origin: google/guava
/**
* Tests null checks against the instance methods of the return values, if any.
*
* <p>Test fails if default value cannot be determined for a constructor or factory method
* parameter, or if the constructor or factory method throws exception.
*
* @return this tester
*/
public FactoryMethodReturnValueTester testNulls() throws Exception {
for (Invokable<?, ?> factory : getFactoriesToTest()) {
Object instance = instantiate(factory);
if (instance != null
&& packagesToTest.contains(Reflection.getPackageName(instance.getClass()))) {
try {
nullPointerTester.testAllPublicInstanceMethods(instance);
} catch (AssertionError e) {
AssertionError error =
new AssertionFailedError("Null check failed on return value of " + factory);
error.initCause(e);
throw error;
}
}
}
return this;
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertUndeliverable(List<Throwable> list, int index, Class<? extends Throwable> clazz, String message) {
Throwable ex = list.get(index);
if (!(ex instanceof UndeliverableException)) {
AssertionError err = new AssertionError("Outer exception UndeliverableException expected but got " + list.get(index));
err.initCause(list.get(index));
throw err;
}
ex = ex.getCause();
if (!clazz.isInstance(ex)) {
AssertionError err = new AssertionError("Inner exception " + clazz + " expected but got " + list.get(index));
err.initCause(list.get(index));
throw err;
}
if (!ObjectHelper.equals(message, ex.getMessage())) {
AssertionError err = new AssertionError("Message " + message + " expected but got " + ex.getMessage());
err.initCause(ex);
throw err;
}
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Throws an {@link AssertionError} with the given message and with the {@link Throwable} that caused the failure.
*
* @param <T> dummy return value type
* @param failureMessage the description of the failed assertion. It can be {@code null}.
* @param realCause cause of the error.
* @return nothing, it's just to be used in doSomething(optional.orElse(() -> fail("boom", cause)));.
* @throws AssertionError with the given message and with the {@link Throwable} that caused the failure.
*/
public static <T> T fail(String failureMessage, Throwable realCause) {
AssertionError error = Failures.instance().failure(failureMessage);
error.initCause(realCause);
throw error;
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Validates that the given class, when forcefully instantiated throws
* an IllegalArgumentException("No instances!") exception.
* @param clazz the class to test, not null
*/
public static void checkUtilityClass(Class<?> clazz) {
try {
Constructor<?> c = clazz.getDeclaredConstructor();
c.setAccessible(true);
try {
c.newInstance();
fail("Should have thrown InvocationTargetException(IllegalStateException)");
} catch (InvocationTargetException ex) {
assertEquals("No instances!", ex.getCause().getMessage());
}
} catch (Exception ex) {
AssertionError ae = new AssertionError(ex.toString());
ae.initCause(ex);
throw ae;
}
}
代码示例来源:origin: google/guava
/**
* Returns the URLs in the class path specified by the {@code java.class.path} {@linkplain
* System#getProperty system property}.
*/
// TODO(b/65488446): Make this a public API.
private static ImmutableList<URL> parseJavaClassPath() {
ImmutableList.Builder<URL> urls = ImmutableList.builder();
for (String entry : Splitter.on(PATH_SEPARATOR.value()).split(JAVA_CLASS_PATH.value())) {
try {
try {
urls.add(new File(entry).toURI().toURL());
} catch (SecurityException e) { // File.toURI checks to see if the file is a directory
urls.add(new URL("file", null, new File(entry).getAbsolutePath()));
}
} catch (MalformedURLException e) {
AssertionError error = new AssertionError("malformed class path entry: " + entry);
error.initCause(e);
throw error;
}
}
return urls.build();
}
代码示例来源:origin: google/guava
/**
* Returns the URLs in the class path specified by the {@code java.class.path} {@linkplain
* System#getProperty system property}.
*/
// TODO(b/65488446): Make this a public API.
static URL[] parseJavaClassPath() {
ImmutableList.Builder<URL> urls = ImmutableList.builder();
for (String entry : Splitter.on(PATH_SEPARATOR.value()).split(JAVA_CLASS_PATH.value())) {
try {
try {
urls.add(new File(entry).toURI().toURL());
} catch (SecurityException e) { // File.toURI checks to see if the file is a directory
urls.add(new URL("file", null, new File(entry).getAbsolutePath()));
}
} catch (MalformedURLException e) {
AssertionError error = new AssertionError("malformed class path entry: " + entry);
error.initCause(e);
throw error;
}
}
return urls.build().toArray(new URL[0]);
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Fails with the given message and with the {@link Throwable} that caused the failure.
*
* @param failureMessage error message.
* @param realCause cause of the error.
* @since 2.6.0 / 3.6.0
*/
public void fail(String failureMessage, Throwable realCause) {
AssertionError error = Failures.instance().failure(failureMessage);
error.initCause(realCause);
proxies.collectError(error);
}
代码示例来源:origin: google/guava
/**
* Returns the URLs in the class path specified by the {@code java.class.path} {@linkplain
* System#getProperty system property}.
*/
// TODO(b/65488446): Make this a public API.
@GwtIncompatible
private static ImmutableList<URL> parseJavaClassPath() {
ImmutableList.Builder<URL> urls = ImmutableList.builder();
for (String entry : Splitter.on(PATH_SEPARATOR.value()).split(JAVA_CLASS_PATH.value())) {
try {
try {
urls.add(new File(entry).toURI().toURL());
} catch (SecurityException e) { // File.toURI checks to see if the file is a directory
urls.add(new URL("file", null, new File(entry).getAbsolutePath()));
}
} catch (MalformedURLException e) {
AssertionError error = new AssertionError("malformed class path entry: " + entry);
error.initCause(e);
throw error;
}
}
return urls.build();
}
}
内容来源于网络,如有侵权,请联系作者删除!