Migrate Kotlin Mockito tests to Mockk
Closes gh-22345
This commit is contained in:
@@ -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,13 +16,9 @@
|
||||
|
||||
package org.springframework.beans.factory
|
||||
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.ArgumentMatchers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
import org.springframework.core.ResolvableType
|
||||
|
||||
/**
|
||||
@@ -30,23 +26,21 @@ import org.springframework.core.ResolvableType
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class BeanFactoryExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var bf: BeanFactory
|
||||
val bf = mockk<BeanFactory>(relaxed = true)
|
||||
|
||||
@Test
|
||||
fun `getBean with reified type parameters`() {
|
||||
bf.getBean<Foo>()
|
||||
verify(bf, times(1)).getBean(Foo::class.java)
|
||||
verify { bf.getBean(Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBean with String and reified type parameters`() {
|
||||
val name = "foo"
|
||||
bf.getBean<Foo>(name)
|
||||
verify(bf, times(1)).getBean(name, Foo::class.java)
|
||||
verify { bf.getBean(name, Foo::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,13 +48,13 @@ class BeanFactoryExtensionsTests {
|
||||
val arg1 = "arg1"
|
||||
val arg2 = "arg2"
|
||||
bf.getBean<Foo>(arg1, arg2)
|
||||
verify(bf, times(1)).getBean(Foo::class.java, arg1, arg2)
|
||||
verify { bf.getBean(Foo::class.java, arg1, arg2) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanProvider with reified type parameters`() {
|
||||
bf.getBeanProvider<Foo>()
|
||||
verify(bf, times(1)).getBeanProvider<ObjectProvider<Foo>>(ArgumentMatchers.any<ResolvableType>())
|
||||
verify { bf.getBeanProvider<ObjectProvider<Foo>>(ofType<ResolvableType>()) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
@@ -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,77 +16,72 @@
|
||||
|
||||
package org.springframework.beans.factory
|
||||
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Answers
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.*
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
/**
|
||||
* Mock object based tests for ListableBeanFactory Kotlin extensions
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class ListableBeanFactoryExtensionsTests {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_MOCKS)
|
||||
lateinit var lbf: ListableBeanFactory
|
||||
val lbf = mockk<ListableBeanFactory>(relaxed = true)
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters`() {
|
||||
lbf.getBeanNamesForType<Foo>()
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, true , true)
|
||||
verify { lbf.getBeanNamesForType(Foo::class.java, true , true) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters and Boolean`() {
|
||||
lbf.getBeanNamesForType<Foo>(false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , true)
|
||||
verify { lbf.getBeanNamesForType(Foo::class.java, false , true) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForType with reified type parameters, Boolean and Boolean`() {
|
||||
lbf.getBeanNamesForType<Foo>(false, false)
|
||||
verify(lbf, times(1)).getBeanNamesForType(Foo::class.java, false , false)
|
||||
verify { lbf.getBeanNamesForType(Foo::class.java, false , false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters`() {
|
||||
lbf.getBeansOfType<Foo>()
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, true , true)
|
||||
verify { lbf.getBeansOfType(Foo::class.java, true , true) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters and Boolean`() {
|
||||
lbf.getBeansOfType<Foo>(false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , true)
|
||||
verify { lbf.getBeansOfType(Foo::class.java, false , true) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansOfType with reified type parameters, Boolean and Boolean`() {
|
||||
lbf.getBeansOfType<Foo>(false, false)
|
||||
verify(lbf, times(1)).getBeansOfType(Foo::class.java, false , false)
|
||||
verify { lbf.getBeansOfType(Foo::class.java, false , false) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeanNamesForAnnotation with reified type parameters`() {
|
||||
lbf.getBeanNamesForAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeanNamesForAnnotation(Bar::class.java)
|
||||
verify { lbf.getBeanNamesForAnnotation(Bar::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getBeansWithAnnotation with reified type parameters`() {
|
||||
lbf.getBeansWithAnnotation<Bar>()
|
||||
verify(lbf, times(1)).getBeansWithAnnotation(Bar::class.java)
|
||||
verify { lbf.getBeansWithAnnotation(Bar::class.java) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `findAnnotationOnBean with String and reified type parameters`() {
|
||||
val name = "bar"
|
||||
lbf.findAnnotationOnBean<Bar>(name)
|
||||
verify(lbf, times(1)).findAnnotationOnBean(name, Bar::class.java)
|
||||
verify { lbf.findAnnotationOnBean(name, Bar::class.java) }
|
||||
}
|
||||
|
||||
class Foo
|
||||
|
||||
Reference in New Issue
Block a user