本文整理了Java中org.assertj.core.api.Assertions.assertThatExceptionOfType()
方法的一些代码示例,展示了Assertions.assertThatExceptionOfType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assertions.assertThatExceptionOfType()
方法的具体详情如下:
包路径:org.assertj.core.api.Assertions
类名称:Assertions
方法名:assertThatExceptionOfType
[英]Entry point to check that an exception of type T is thrown by a given throwingCallablewhich allows to chain assertions on the thrown exception.
Example:
assertThatExceptionOfType(IOException.class)
.isThrownBy(() -> { throw new IOException("boom!"); })
.withMessage("boom!");
This method is more or less the same of #assertThatThrownBy(ThrowableAssert.ThrowingCallable) but in a more natural way.
[中]用于检查给定ThrowingCallables是否引发T类型异常的入口点,该入口点允许对引发的异常链接断言。
例子:
assertThatExceptionOfType(IOException.class)
.isThrownBy(() -> { throw new IOException("boom!"); })
.withMessage("boom!");
此方法与#assertThatThrownBy(ThrowableAssert.ThrowingCallable)大致相同,但更自然。
代码示例来源:origin: org.assertj/assertj-core
/**
* Alias for {@link #assertThatExceptionOfType(Class)} for {@link IllegalStateException}.
*
* @return the created {@link ThrowableTypeAssert}.
*
* @since 3.7.0
*/
@CheckReturnValue
public static ThrowableTypeAssert<IllegalStateException> assertThatIllegalStateException() {
return assertThatExceptionOfType(IllegalStateException.class);
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Alias for {@link #assertThatExceptionOfType(Class)} for {@link NullPointerException}.
*
* @return the created {@link ThrowableTypeAssert}.
*
* @since 3.7.0
*/
@CheckReturnValue
public static ThrowableTypeAssert<NullPointerException> assertThatNullPointerException() {
return assertThatExceptionOfType(NullPointerException.class);
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Alias for {@link #assertThatExceptionOfType(Class)} for {@link IllegalArgumentException}.
*
* @return the created {@link ThrowableTypeAssert}.
*
* @since 3.7.0
*/
@CheckReturnValue
public static ThrowableTypeAssert<IllegalArgumentException> assertThatIllegalArgumentException() {
return assertThatExceptionOfType(IllegalArgumentException.class);
}
代码示例来源:origin: org.assertj/assertj-core
/**
* Alias for {@link #assertThatExceptionOfType(Class)} for {@link IOException}.
*
* @return the created {@link ThrowableTypeAssert}.
*
* @since 3.7.0
*/
@CheckReturnValue
public static ThrowableTypeAssert<IOException> assertThatIOException() {
return assertThatExceptionOfType(IOException.class);
}
代码示例来源:origin: spring-projects/spring-security
@Test
public void authenticateWhenPostAuthenticationChecksFail() {
when(this.userDetailsService.findByUsername(any())).thenReturn(Mono.just(this.user));
doThrow(new LockedException("account is locked")).when(this.postAuthenticationChecks).check(any());
when(this.encoder.matches(any(), any())).thenReturn(true);
this.manager.setPasswordEncoder(this.encoder);
this.manager.setPostAuthenticationChecks(this.postAuthenticationChecks);
assertThatExceptionOfType(LockedException.class)
.isThrownBy(() -> this.manager.authenticate(new UsernamePasswordAuthenticationToken(this.user, this.user.getPassword())).block())
.withMessage("account is locked");
verify(this.postAuthenticationChecks).check(eq(this.user));
}
代码示例来源:origin: prestodb/presto
@Test
public void testFloat()
throws ParquetCorruptionException
{
String column = "FloatColumn";
assertEquals(getDomain(REAL, 0, null, ID, column, true), all(REAL));
float minimum = 4.3f;
float maximum = 40.3f;
assertEquals(getDomain(REAL, 10, floatColumnStats(minimum, minimum), ID, column, true), singleValue(REAL, (long) floatToRawIntBits(minimum)));
assertEquals(
getDomain(REAL, 10, floatColumnStats(minimum, maximum), ID, column, true),
create(ValueSet.ofRanges(range(REAL, (long) floatToRawIntBits(minimum), true, (long) floatToRawIntBits(maximum), true)), false));
// ignore corrupted statistics
assertEquals(getDomain(REAL, 10, floatColumnStats(maximum, minimum), ID, column, false), create(ValueSet.all(REAL), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(REAL, 10, floatColumnStats(maximum, minimum), ID, column, true))
.withMessage("Corrupted statistics for column \"FloatColumn\" in Parquet file \"testFile\": [min: 40.30000, max: 4.30000, num_nulls: 0]");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyCompleteUsesDefaultTimeout() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() ->
StepVerifier.create(Mono.delay(Duration.ofMillis(150)))
.verifyComplete())
.withMessageStartingWith("VerifySubscriber timed out");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyErrorUsesDefaultTimeout() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() ->
StepVerifier.create(Mono.delay(Duration.ofMillis(150)))
.verifyError())
.withMessageStartingWith("VerifySubscriber timed out");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyErrorMatchesUsesDefaultTimeout() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() ->
StepVerifier.create(Mono.delay(Duration.ofMillis(150)))
.verifyErrorMatches(ignore -> true))
.withMessageStartingWith("VerifySubscriber timed out");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void noEventExpectationButError() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(StepVerifier.create(Flux.error(new IllegalStateException("boom")).hide())
.expectSubscription()
.expectNoEvent(Duration.ofMillis(50))
.expectComplete()
::verify)
.withMessage("Unexpected error during a no-event expectation: java.lang.IllegalStateException: boom")
.withCause(new IllegalStateException("boom"));
}
代码示例来源:origin: prestodb/presto
@Test
public void testDate()
throws ParquetCorruptionException
{
String column = "DateColumn";
assertEquals(getDomain(DATE, 0, null, ID, column, true), all(DATE));
assertEquals(getDomain(DATE, 10, intColumnStats(100, 100), ID, column, true), singleValue(DATE, 100L));
assertEquals(getDomain(DATE, 10, intColumnStats(0, 100), ID, column, true), create(ValueSet.ofRanges(range(DATE, 0L, true, 100L, true)), false));
// ignore corrupted statistics
assertEquals(getDomain(DATE, 10, intColumnStats(200, 100), ID, column, false), create(ValueSet.all(DATE), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(DATE, 10, intColumnStats(200, 100), ID, column, true))
.withMessage("Corrupted statistics for column \"DateColumn\" in Parquet file \"testFile\": [min: 200, max: 100, num_nulls: 0]");
}
代码示例来源:origin: prestodb/presto
@Test
public void testDouble()
throws ParquetCorruptionException
{
String column = "DoubleColumn";
assertEquals(getDomain(DOUBLE, 0, null, ID, column, true), all(DOUBLE));
assertEquals(getDomain(DOUBLE, 10, doubleColumnStats(42.24, 42.24), ID, column, true), singleValue(DOUBLE, 42.24));
assertEquals(getDomain(DOUBLE, 10, doubleColumnStats(3.3, 42.24), ID, column, true), create(ValueSet.ofRanges(range(DOUBLE, 3.3, true, 42.24, true)), false));
// ignore corrupted statistics
assertEquals(getDomain(DOUBLE, 10, doubleColumnStats(42.24, 3.3), ID, column, false), create(ValueSet.all(DOUBLE), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(DOUBLE, 10, doubleColumnStats(42.24, 3.3), ID, column, true))
.withMessage("Corrupted statistics for column \"DoubleColumn\" in Parquet file \"testFile\": [min: 42.24000, max: 3.30000, num_nulls: 0]");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void expectNextSequenceWithPartialMatchingSequenceNoMoreExpectation() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> StepVerifier.create(Flux.range(1, 5))
.expectNextSequence(Arrays.asList(1, 2, 3))
.verifyComplete())
.withMessage("expectation \"expectComplete\" failed (expected: onComplete(); actual: onNext(4))");
}
代码示例来源:origin: prestodb/presto
@Test
public void testBigint()
throws ParquetCorruptionException
{
String column = "BigintColumn";
assertEquals(getDomain(BIGINT, 0, null, ID, column, true), all(BIGINT));
assertEquals(getDomain(BIGINT, 10, longColumnStats(100L, 100L), ID, column, true), singleValue(BIGINT, 100L));
assertEquals(getDomain(BIGINT, 10, longColumnStats(0L, 100L), ID, column, true), create(ValueSet.ofRanges(range(BIGINT, 0L, true, 100L, true)), false));
// ignore corrupted statistics
assertEquals(getDomain(BIGINT, 10, longColumnStats(100L, 0L), ID, column, false), create(ValueSet.all(BIGINT), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(BIGINT, 10, longColumnStats(100L, 10L), ID, column, true))
.withMessage("Corrupted statistics for column \"BigintColumn\" in Parquet file \"testFile\": [min: 100, max: 10, num_nulls: 0]");
}
代码示例来源:origin: prestodb/presto
@Test
public void testInteger()
throws ParquetCorruptionException
{
String column = "IntegerColumn";
assertEquals(getDomain(INTEGER, 0, null, ID, column, true), all(INTEGER));
assertEquals(getDomain(INTEGER, 10, longColumnStats(100, 100), ID, column, true), singleValue(INTEGER, 100L));
assertEquals(getDomain(INTEGER, 10, longColumnStats(0, 100), ID, column, true), create(ValueSet.ofRanges(range(INTEGER, 0L, true, 100L, true)), false));
assertEquals(getDomain(INTEGER, 20, longColumnStats(0, 2147483648L), ID, column, true), notNull(INTEGER));
// ignore corrupted statistics
assertEquals(getDomain(INTEGER, 10, longColumnStats(2147483648L, 0), ID, column, false), create(ValueSet.all(INTEGER), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(INTEGER, 10, longColumnStats(2147483648L, 10), ID, column, true))
.withMessage("Corrupted statistics for column \"IntegerColumn\" in Parquet file \"testFile\": [min: 2147483648, max: 10, num_nulls: 0]");
}
代码示例来源:origin: prestodb/presto
@Test
public void testTinyint()
throws ParquetCorruptionException
{
String column = "TinyintColumn";
assertEquals(getDomain(TINYINT, 0, null, ID, column, true), all(TINYINT));
assertEquals(getDomain(TINYINT, 10, longColumnStats(100, 100), ID, column, true), singleValue(TINYINT, 100L));
assertEquals(getDomain(TINYINT, 10, longColumnStats(0, 100), ID, column, true), create(ValueSet.ofRanges(range(TINYINT, 0L, true, 100L, true)), false));
assertEquals(getDomain(TINYINT, 20, longColumnStats(0, 2147483648L), ID, column, true), notNull(TINYINT));
// ignore corrupted statistics
assertEquals(getDomain(TINYINT, 10, longColumnStats(2147483648L, 0), ID, column, false), create(ValueSet.all(TINYINT), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(TINYINT, 10, longColumnStats(2147483648L, 10), ID, column, true))
.withMessage("Corrupted statistics for column \"TinyintColumn\" in Parquet file \"testFile\": [min: 2147483648, max: 10, num_nulls: 0]");
}
代码示例来源:origin: prestodb/presto
@Test
public void testSmallint()
throws ParquetCorruptionException
{
String column = "SmallintColumn";
assertEquals(getDomain(SMALLINT, 0, null, ID, column, true), all(SMALLINT));
assertEquals(getDomain(SMALLINT, 10, longColumnStats(100, 100), ID, column, true), singleValue(SMALLINT, 100L));
assertEquals(getDomain(SMALLINT, 10, longColumnStats(0, 100), ID, column, true), create(ValueSet.ofRanges(range(SMALLINT, 0L, true, 100L, true)), false));
assertEquals(getDomain(SMALLINT, 20, longColumnStats(0, 2147483648L), ID, column, true), notNull(SMALLINT));
// ignore corrupted statistics
assertEquals(getDomain(SMALLINT, 10, longColumnStats(2147483648L, 0), ID, column, false), create(ValueSet.all(SMALLINT), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(SMALLINT, 10, longColumnStats(2147483648L, 10), ID, column, true))
.withMessage("Corrupted statistics for column \"SmallintColumn\" in Parquet file \"testFile\": [min: 2147483648, max: 10, num_nulls: 0]");
}
代码示例来源:origin: reactor/reactor-core
@Test(timeout = 1000L)
public void thenConsumeWhileLowRequestShortcircuits() {
StepVerifier.Step<Integer> validSoFar = StepVerifier.create(Flux.just(1, 2), 1)
.expectNext(1);
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> validSoFar.thenConsumeWhile(s -> s == 1))
.withMessageStartingWith("The scenario will hang at thenConsumeWhile due to too little request being performed for the expectations to finish; ")
.withMessageEndingWith("request remaining since last step: 0, expected: at least 1 (best effort estimation)");
}
代码示例来源:origin: prestodb/presto
@Test
public void testString()
throws ParquetCorruptionException
{
String column = "StringColumn";
assertEquals(getDomain(createUnboundedVarcharType(), 0, null, ID, column, true), all(createUnboundedVarcharType()));
assertEquals(getDomain(createUnboundedVarcharType(), 10, stringColumnStats("taco", "taco"), ID, column, true), singleValue(createUnboundedVarcharType(), utf8Slice("taco")));
assertEquals(getDomain(createUnboundedVarcharType(), 10, stringColumnStats("apple", "taco"), ID, column, true), create(ValueSet.ofRanges(range(createUnboundedVarcharType(), utf8Slice("apple"), true, utf8Slice("taco"), true)), false));
assertEquals(getDomain(createUnboundedVarcharType(), 10, stringColumnStats("中国", "美利坚"), ID, column, true), create(ValueSet.ofRanges(range(createUnboundedVarcharType(), utf8Slice("中国"), true, utf8Slice("美利坚"), true)), false));
// ignore corrupted statistics
assertEquals(getDomain(createUnboundedVarcharType(), 10, stringColumnStats("taco", "apple"), ID, column, false), create(ValueSet.all(createUnboundedVarcharType()), false));
// fail on corrupted statistics
assertThatExceptionOfType(ParquetCorruptionException.class)
.isThrownBy(() -> getDomain(createUnboundedVarcharType(), 10, stringColumnStats("taco", "apple"), ID, column, true))
.withMessage("Corrupted statistics for column \"StringColumn\" in Parquet file \"testFile\": [min: taco, max: apple, num_nulls: 0]");
}
代码示例来源:origin: reactor/reactor-core
@Test
public void verifyVirtualTimeNoEventNeverError() {
assertThatExceptionOfType(AssertionError.class)
.isThrownBy(() -> StepVerifier.withVirtualTime(() -> Mono.never()
.log())
.expectNoEvent(Duration.ofDays(10000))
.thenCancel()
.verify())
.withMessageStartingWith("expectation failed (expected no event: onSubscribe(");
}
内容来源于网络,如有侵权,请联系作者删除!