Skip to content

Instantly share code, notes, and snippets.

@robfletcher
Last active March 18, 2019 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robfletcher/430b03bee30d68f2cff2055fc9122977 to your computer and use it in GitHub Desktop.
Save robfletcher/430b03bee30d68f2cff2055fc9122977 to your computer and use it in GitHub Desktop.
import io.mockk.Called
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
import java.util.function.Consumer
import java.util.function.Supplier
class NullOrUnitWasNotCalled {
@Test
fun unitFnWasNotCalled() {
val consumer: Consumer<String> = mockk(relaxUnitFun = true)
verify { consumer.accept(any()) wasNot Called }
}
@Test
fun nullFnWasNotCalled() {
val supplier: Supplier<String?> = mockk()
verify { supplier.get()?.wasNot(Called) }
}
}
@robfletcher
Copy link
Author

java.lang.AssertionError: Verification failed: call 1 of 1: Consumer(#7).accept(any())) was not called

java.lang.AssertionError: Verification failed: call 1 of 1: Supplier(#4).get()) was not called

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment