Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions mockito-kotlin/src/main/kotlin/org/mockito/kotlin/MockedStatic.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* The MIT License
*
* Copyright (c) 2018 Niek Haarman
* Copyright (c) 2007 Mockito contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.mockito.kotlin

import org.mockito.MockedStatic
import org.mockito.verification.VerificationMode

/**
* Syntax sugar to enable [SAM conversion syntax](https://kotlinlang.org/docs/java-interop.html#sam-conversions)
* for [MockedStatic.verify] with a [VerificationMode].
*
* Example:
* ```
* fooMockedStatic.verify(times(3)) { Foo.doSomething() }
* ```
*/
fun <T> MockedStatic<T>.verify(mode: VerificationMode, verification: MockedStatic.Verification) {
verify(verification, mode)
}
5 changes: 5 additions & 0 deletions tests/src/test/kotlin/test/Classes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ interface GenericMethods<T> {
}

class ThrowableClass(cause: Throwable) : Throwable(cause)

object SomeObject {
@JvmStatic
fun aStaticMethod() {}
}
19 changes: 19 additions & 0 deletions tests/src/test/kotlin/test/MockedStaticTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test

import org.junit.Test
import org.mockito.Mockito.mockStatic
import org.mockito.kotlin.times
import org.mockito.kotlin.verify

class MockedStaticTest : TestBase() {

@Test
fun testVerifyExtensionFun() {
mockStatic(SomeObject::class.java).use { mocked ->
SomeObject.aStaticMethod()
SomeObject.aStaticMethod()

mocked.verify(times(2)) { SomeObject.aStaticMethod() }
}
}
}