notToBeAnInstanceOf

Expects that the type of the subject of this expectation is not the defined SubTypeOfSubjectT neither a subtype thereof.

Notice, this function has only one type parameter in order that you do not have to restate the type of the current subject. But that also means that we need to return Expect<*> or in other words, we loose the type of the subject. Which means, if you want to state a further expectation after notToBeAnInstanceOf then you most likely want to use the overload which expects one (or more) KClass instead which keeps the type of the initial subject.

Return

an Expect for the subject of this expectation but untyped (with a star projection).

Since

1.1.0

Parameters

SubTypeOfSubjectT

the type which we do not expect to be the same or a super-type of the subject of this expectation.

Samples

val n: Number = 16L
expect(n).notToBeAnInstanceOf<Int>()
fails {
    // fails because n is actually instance of Long
    expect(n).notToBeAnInstanceOf<Long>()
}

fun <T> Expect<T>.notToBeAnInstanceOf(type: KClass<*>, vararg otherTypes: KClass<*>): Expect<T>(source)

Expects that the type of the subject of this expectation is not the given type neither a subtype thereof and same same for the otherTypes.

Return

an Expect for the subject of this expectation.

Since

1.1.0

Parameters

type

one of the types which we do not expect to be the same or a super-type of the type of the subject of this expectation.

otherTypes

all types which we do not expect to be the same or a super-type of the type of the subject of this expectation.

Samples

val n: Number = 16L
expect(n).notToBeAnInstanceOf(Int::class, Float::class, Double::class)
fails {
    // fails because n is actually instance of Long
    expect(n).notToBeAnInstanceOf(Int::class, Long::class)
}