Migrate Kotlin Mockito tests to Mockk
Closes gh-22345
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,17 +16,11 @@
|
||||
|
||||
package org.springframework.test.web.reactive.server
|
||||
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import com.nhaarman.mockito_kotlin.times
|
||||
import com.nhaarman.mockito_kotlin.verify
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.reactivestreams.Publisher
|
||||
import org.springframework.web.reactive.function.server.ServerResponse.*
|
||||
import org.springframework.web.reactive.function.server.router
|
||||
|
||||
/**
|
||||
@@ -34,27 +28,24 @@ import org.springframework.web.reactive.function.server.router
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class WebTestClientExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var requestBodySpec: WebTestClient.RequestBodySpec
|
||||
val requestBodySpec = mockk<WebTestClient.RequestBodySpec>(relaxed = true)
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var responseSpec: WebTestClient.ResponseSpec
|
||||
val responseSpec = mockk<WebTestClient.ResponseSpec>(relaxed = true)
|
||||
|
||||
|
||||
@Test
|
||||
fun `RequestBodySpec#body with Publisher and reified type parameters`() {
|
||||
val body = mock<Publisher<Foo>>()
|
||||
val body = mockk<Publisher<Foo>>()
|
||||
requestBodySpec.body(body)
|
||||
verify(requestBodySpec, times(1)).body(body, Foo::class.java)
|
||||
verify { requestBodySpec.body(body, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#expectBody with reified type parameters`() {
|
||||
responseSpec.expectBody<Foo>()
|
||||
verify(responseSpec, times(1)).expectBody(Foo::class.java)
|
||||
verify { responseSpec.expectBody(Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,13 +75,13 @@ class WebTestClientExtensionsTests {
|
||||
@Test
|
||||
fun `ResponseSpec#expectBodyList with reified type parameters`() {
|
||||
responseSpec.expectBodyList<Foo>()
|
||||
verify(responseSpec, times(1)).expectBodyList(Foo::class.java)
|
||||
verify { responseSpec.expectBodyList(Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ResponseSpec#returnResult with reified type parameters`() {
|
||||
responseSpec.returnResult<Foo>()
|
||||
verify(responseSpec, times(1)).returnResult(Foo::class.java)
|
||||
verify { responseSpec.returnResult(Foo::class.java) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,33 +16,26 @@
|
||||
|
||||
package org.springframework.test.web.servlet.result
|
||||
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import com.nhaarman.mockito_kotlin.times
|
||||
import com.nhaarman.mockito_kotlin.verify
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.hamcrest.Matcher
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class StatusResultMatchersExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var matchers: StatusResultMatchers
|
||||
val matchers = mockk<StatusResultMatchers>(relaxed = true)
|
||||
|
||||
@Test
|
||||
fun `StatusResultMatchers#is with Matcher parameter is called as expected when using isEqualTo extension`() {
|
||||
val matcher = mock<Matcher<Int>>()
|
||||
val matcher = mockk<Matcher<Int>>()
|
||||
matchers.isEqualTo(matcher)
|
||||
verify(matchers, times(1)).`is`(matcher)
|
||||
verify { matchers.`is`(matcher) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `StatusResultMatchers#is with int parameter is called as expected when using isEqualTo extension`() {
|
||||
matchers.isEqualTo(200)
|
||||
verify(matchers, times(1)).`is`(200)
|
||||
verify { matchers.`is`(200) }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user