本文整理了Java中java.lang.AssertionError
类的一些代码示例,展示了AssertionError
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AssertionError
类的具体详情如下:
包路径:java.lang.AssertionError
类名称:AssertionError
[英]Thrown when an assertion has failed.
[中]当断言失败时抛出。
代码示例来源:origin: ReactiveX/RxJava
/**
* Assert that the upstream is a fuseable source.
* <p>Package-private: avoid leaking the now internal fusion properties into the public API.
* Use ObserverFusion to work with such tests.
* @return this
*/
final TestObserver<T> assertFuseable() {
if (qd == null) {
throw new AssertionError("Upstream is not fuseable.");
}
return this;
}
代码示例来源:origin: square/okhttp
/**
* Returns true if {@code e} is due to a firmware bug fixed after Android 4.2.2.
* https://code.google.com/p/android/issues/detail?id=54072
*/
public static boolean isAndroidGetsocknameError(AssertionError e) {
return e.getCause() != null && e.getMessage() != null
&& e.getMessage().contains("getsockname failed");
}
代码示例来源: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: ReactiveX/RxJava
@Test
public void assertValueSetMissing() {
Set<Integer> set = new HashSet<Integer>(Arrays.asList(0, 1, 2, 4, 5, 6, 7));
try {
Observable.range(1, 5)
.test()
.assertValueSet(set);
throw new RuntimeException("Should have failed");
} catch (AssertionError ex) {
assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3));
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void assertNoTimeout2() {
try {
Flowable.never()
.test()
.awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50)
.assertNoTimeout();
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.getMessage().contains("Timeout?!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void assertValueSetMissing() {
Set<Integer> set = new HashSet<Integer>(Arrays.asList(0, 1, 2, 4, 5, 6, 7));
try {
Flowable.range(1, 5)
.test()
.assertValueSet(set);
throw new RuntimeException("Should have failed");
} catch (AssertionError ex) {
assertTrue(ex.getMessage(), ex.getMessage().contains("Value not in the expected collection: " + 3));
}
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void assertTimeout2() {
try {
Flowable.empty()
.test()
.awaitCount(1, TestWaitStrategy.SLEEP_1MS, 50)
.assertTimeout();
throw new RuntimeException("Should have thrown!");
} catch (AssertionError ex) {
assertTrue(ex.toString(), ex.getMessage().contains("No timeout?!"));
}
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Assert that the upstream is not a fuseable source.
* <p>Package-private: avoid leaking the now internal fusion properties into the public API.
* Use ObserverFusion to work with such tests.
* @return this
*/
final TestObserver<T> assertNotFuseable() {
if (qd != null) {
throw new AssertionError("Upstream is fuseable.");
}
return this;
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void headerContainsWithMissingHeader() throws Exception {
AssertionError error = assertThrows(AssertionError.class,
() -> MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request));
assertThat(error.getMessage(), containsString("but was null"));
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Assert that the upstream is a fuseable source.
* <p>Package-private: avoid leaking the now internal fusion properties into the public API.
* Use SubscriberFusion to work with such tests.
* @return this
*/
final TestSubscriber<T> assertFuseable() {
if (qs == null) {
throw new AssertionError("Upstream is not fuseable.");
}
return this;
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void queryParamContainsWithMissingValue() throws Exception {
this.request.setURI(new URI("http://foo.com/a?foo=bar&foo=baz"));
AssertionError error = assertThrows(AssertionError.class,
() -> MockRestRequestMatchers.queryParam("foo", containsString("bx")).match(this.request));
assertThat(error.getMessage(), containsString("was \"bar\""));
}
代码示例来源:origin: ReactiveX/RxJava
/**
* Assert that the upstream is not a fuseable source.
* <p>Package-private: avoid leaking the now internal fusion properties into the public API.
* Use SubscriberFusion to work with such tests.
* @return this
*/
final TestSubscriber<T> assertNotFuseable() {
if (qs != null) {
throw new AssertionError("Upstream is fuseable.");
}
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: spring-projects/spring-framework
@Test
public void headerMissing() throws Exception {
AssertionError error = assertThrows(AssertionError.class,
() -> MockRestRequestMatchers.header("foo", "bar").match(this.request));
assertThat(error.getMessage(), containsString("was null"));
}
代码示例来源:origin: square/okhttp
/** Throws {@code throwable} as either an IOException, RuntimeException, or Error. */
private static IOException propagate(Throwable throwable) throws IOException {
if (throwable instanceof IOException) throw (IOException) throwable;
if (throwable instanceof Error) throw (Error) throwable;
if (throwable instanceof RuntimeException) throw (RuntimeException) throwable;
throw new AssertionError();
}
代码示例来源: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: spring-projects/spring-framework
@Test
public void headersWithMissingHeader() throws Exception {
AssertionError error = assertThrows(AssertionError.class,
() -> MockRestRequestMatchers.header("foo", "bar").match(this.request));
assertThat(error.getMessage(), containsString("but was null"));
}
代码示例来源:origin: google/guava
@Override
Cut<Comparable<?>> withUpperBoundType(
BoundType boundType, DiscreteDomain<Comparable<?>> domain) {
throw new AssertionError("this statement should be unreachable");
}
内容来源于网络,如有侵权,请联系作者删除!