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>()
}

infix fun <T> Expect<T>.notToBeAnInstanceOf(type: KClass<*>): Expect<T>(source)

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

Return

an Expect for the subject of this expectation.

Since

1.1.0

Parameters

type

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::class
fails {
    // fails because n is actually instance of Long
    expect(n) notToBeAnInstanceOf Long::class
}

infix fun <T> Expect<T>.notToBeAnInstanceOf(types: Types): Expect<T>(source)

Expects that the type of the subject of this expectation is not one of the given types neither a subtype thereof.

Return

an Expect for the subject of this expectation.

Since

1.1.0

Parameters

types

the types 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 types(Int::class, Float::class, Double::class)
fails {
    // fails because n is actually instance of Long
    expect(n) notToBeAnInstanceOf types(Int::class, Long::class)
}