assertThat

fun <T> assertThat(actual: T, matcher: Matcher<in T>)

Deprecated

use {@code MatcherAssert.assertThat()}

Asserts that actual satisfies the condition specified by matcher. If not, an AssertionError is thrown with information about the matcher and failing value. Example:

assertThat(0, is(1)); // fails:
// failure message:
// expected: is <1>
// got value: <0>
assertThat(0, is(not(1))) // passes
*

Matcher does not currently document the meaning of its type parameter T. This method assumes that a matcher typed as Matcher<T> can be meaningfully applied only to values that could be assigned to a variable of type T.

Parameters

the static type accepted by the matcher (this can flag obvious compile-time problems such as `assertThat(1, is("a"))`
actual

the computed value being compared

matcher

an expression, built of Matchers, specifying allowed values

See also

org.hamcrest.CoreMatchers

fun <T> assertThat(reason: String, actual: T, matcher: Matcher<in T>)

Deprecated

use {@code MatcherAssert.assertThat()}

Asserts that actual satisfies the condition specified by matcher. If not, an AssertionError is thrown with the reason and information about the matcher and failing value. Example:

assertThat("Help! Integers don't work", 0, is(1)); // fails:
// failure message:
// Help! Integers don't work
// expected: is <1>
// got value: <0>
assertThat("Zero is one", 0, is(not(1))) // passes
*

Matcher does not currently document the meaning of its type parameter T. This method assumes that a matcher typed as Matcher<T> can be meaningfully applied only to values that could be assigned to a variable of type T.

Parameters

reason

additional information about the error

the static type accepted by the matcher (this can flag obvious compile-time problems such as `assertThat(1, is("a"))`
actual

the computed value being compared

matcher

an expression, built of Matchers, specifying allowed values

See also

org.hamcrest.CoreMatchers