assertk / assertk / Assert

Assert

(common, jvm) sealed class Assert<out T>

An assertion. Holds an actual value to assertion on and an optional name.

See Also

assertThat

Properties

(common, jvm)

name

val name: String?

Functions

(common, jvm)

assertThat

Asserts on the given value with an optional name.

abstract fun <R> assertThat(actual: R, name: String? = this.name): Assert<R>
(common, jvm)

given

Allows checking the actual value of an assert. This can be used to build your own custom assertions.

fun given(assertion: (T) -> Unit): Unit
(common, jvm)

transform

Transforms an assertion from one type to another. If the assertion is failing the resulting assertion will still be failing, otherwise the mapping function is called. An optional name can be provided, otherwise this assertion's name will be used.

fun <R> transform(name: String? = this.name, transform: (T) -> R): Assert<R>

Extension Functions

(jvm)

bytes

Returns an assert on the file's contents as bytes.

fun Assert<File>.bytes(): Assert<ByteArray>

Assert on file bytes

fun Assert<Path>.bytes(): Assert<ByteArray>
(jvm)

doesNotHaveClass

Asserts the value does not have the expected java class. This is an exact match, so assertThat("test").doesNotHaveClass(String::class.java) is fails but assertThat("test").doesNotHaveClass(Any::class.java) is successful.

fun <T : Any> Assert<T>.doesNotHaveClass(jclass: Class<out T>): Unit
(jvm)

exists

Asserts the file exists.

fun Assert<File>.exists(): Unit
(jvm)

extension

Returns an assert on the file's extension.

fun Assert<File>.extension(): Assert<String>
(jvm)

hasClass

Asserts the value has the expected java class. This is an exact match, so assertThat("test").hasClass(String::class.java) is successful but assertThat("test").hasClass(Any::class.java) fails.

fun <T : Any> Assert<T>.hasClass(jclass: Class<out T>): Unit
(jvm)

hasDirectChild

Asserts the file has the expected direct child.

fun Assert<File>.hasDirectChild(expected: File): Unit
(jvm)

hasExtension

Asserts the file has the expected extension.

fun Assert<File>.hasExtension(expected: String): Unit
(jvm)

hasName

Asserts the file has the expected name.

fun Assert<File>.hasName(expected: String): Unit
(jvm)

hasNotSameContentAs

Asserts that the actual stream has a different content as the expected stream. Both InputStreams will be closed by the assertion.

fun Assert<InputStream>.hasNotSameContentAs(expected: InputStream): Unit
(jvm)

hasParent

Asserts the file has the expected parent path.

fun Assert<File>.hasParent(expected: String): Unit
(jvm)

hasPath

Asserts the file has the expected path.

fun Assert<File>.hasPath(expected: String): Unit
(jvm)

hasSameContentAs

Asserts that the actual stream has the same content as the expected stream. Both InputStreams will be closed by the assertion.

fun Assert<InputStream>.hasSameContentAs(expected: InputStream): Unit
(jvm)

hasText

Asserts the file contains exactly the expected text (and nothing else).

fun Assert<File>.hasText(expected: String, charset: Charset = Charsets.UTF_8): Unit
(jvm)

isDataClassEqualTo

Like isEqualTo but reports exactly which properties differ. Only supports data classes. Note: you should not use this if your data class has a custom Any.equals since it can be misleading.

fun <T : Any> Assert<T>.isDataClassEqualTo(expected: T): Unit
(jvm)

isDirectory

Asserts the file is a directory.

fun Assert<File>.isDirectory(): Unit

Assert that the path is a directory.

fun Assert<Path>.isDirectory(vararg options: LinkOption): Unit
(jvm)

isEqualByComparingTo

Asserts that actual.compareTo(BigDecimal(expected) == 0.

fun Assert<BigDecimal>.isEqualByComparingTo(expected: String): Unit
(jvm)

isEqualToIgnoringGivenProperties

Returns an assert that compares for all properties except the given properties on the calling class

fun <T : Any> Assert<T>.isEqualToIgnoringGivenProperties(other: T, vararg properties: KProperty1<T, Any?>): Unit
(jvm)

isExecutable

Assert that the path is an executable.

fun Assert<Path>.isExecutable(): Unit
(jvm)

isFile

Asserts the file is a simple file (not a directory).

fun Assert<File>.isFile(): Unit
(jvm)

isHidden

Asserts the file is hidden.

fun Assert<File>.isHidden(): Unit

Assert that the path is hidden.

fun Assert<Path>.isHidden(): Unit
(jvm)

isInstanceOf

Asserts the value is an instance of the expected java class. Both assertThat("test").isInstanceOf(String::class.java) and assertThat("test").isInstanceOf(Any::class.java) is successful.

fun <T : Any, S : T> Assert<T>.isInstanceOf(jclass: Class<S>): Assert<S>
(jvm)

isNotHidden

Asserts the file is not hidden.

fun Assert<File>.isNotHidden(): Unit
(jvm)

isNotInstanceOf

Asserts the value is not an instance of the expected java class. Both assertThat("test").isNotInstanceOf(String::class) and assertThat("test").isNotInstanceOf(Any::class) fails.

fun <T : Any> Assert<T>.isNotInstanceOf(jclass: Class<out T>): Unit
(jvm)

isReadable

Assert that the path is readable.

fun Assert<Path>.isReadable(): Unit
(jvm)

isRegularFile

Assert that the path is a regular file.

fun Assert<Path>.isRegularFile(vararg options: LinkOption): Unit
(jvm)

isSameFileAs

Assert that the path points to the same object as the other path.

fun Assert<Path>.isSameFileAs(expected: Path): Unit
(jvm)

isSymbolicLink

Assert that the path is a symbolic link.

fun Assert<Path>.isSymbolicLink(): Unit
(jvm)

isWritable

Assert that the path is writable link.

fun Assert<Path>.isWritable(): Unit
(jvm)

jClass

Returns an assert on the java class of the value.

fun <T : Any> Assert<T>.jClass(): Assert<Class<out T>>
(jvm)

lines

Assert on file lines

fun Assert<Path>.lines(charset: Charset = Charsets.UTF_8): Assert<List<String>>
(jvm)

name

Returns an assert on the file's name.

fun Assert<File>.name(): Assert<String!>
(jvm)

parent

Returns an assert on the file's parent.

fun Assert<File>.parent(): Assert<String!>
(jvm)

path

Returns an assert on the file's path.

fun Assert<File>.path(): Assert<String!>
(jvm)

prop

Returns an assert that asserts on the given property.

fun <T, P> Assert<T>.prop(callable: KCallable<P>): Assert<P>
(jvm)

stackTrace

Returns an assert on the throwable's stack trace.

fun Assert<Throwable>.stackTrace(): Assert<List<String>>
(jvm)

text

Returns an assert on the file's contents as text.

fun Assert<File>.text(charset: Charset = Charsets.UTF_8): Assert<String>