Questions tagged [mockito-kotlin]

a library for Kotlin that provides helper functions to work with Mockito, a popular mock framework.

A library that provides helper functions to work with Mockito in Kotlin. Mockito is a popular mock framework.

66 questions
0
votes
0 answers

How do i return a void() in the Mockito.when()

Hello i am having difficulties in this particular unit test testing the Repository of my app there is a function that returns void.I think i have to do Mockito.when to define the behaviour of a mocked class. This is my class. package…
0
votes
0 answers

Testing Service layer in Kotlin Spring Boot when back end is using Spring Security

I'm looking to try and test my back end Service layer (ideally along with my Controller layer too). However, I'm not sure how I would be able to go about doing this. I saw that I can use Mockito to do this, however, I was not able to figure out how…
JamieRhys
  • 206
  • 6
  • 24
0
votes
0 answers

How to mock lambda parameter in mockito-kotlin?

I've got an interface: interface DistanceChecker { fun checkDistance(locationData: LocationData, result: (Boolean) -> Unit) } I need to mock this method, but I don't call it explicitly, it's injected into logic. This construction does not work: …
apleuxa12
  • 85
  • 5
0
votes
2 answers

Kotlin Mockito Generics

Suppose my class is: open class TestThis{ @Autowired private var myService : MyService? = null fun doMyFunction(){ val result = myService.doSomething("hello world", Function { entry -> var retVal :…
theAnonymous
  • 1,701
  • 2
  • 28
  • 62
0
votes
1 answer

Missing data in lambda when using mokito's spy

I'm testing my code with mokito-kotlin and I run into a situation where a executed lambda has wrong data. I found out that the "scope" as I know it from JavaScript is different then expected. The this of the lambda is a different one when I use…
rekire
  • 47,260
  • 30
  • 167
  • 264
0
votes
1 answer

Verifying method call with enum in Kotlin

I'm trying to verify that a method is called with a given argument. That argument is a non-nullable enum type. So I get the exception eq(SomeEnum.foo) must not be null. Here is a sample what I'm trying to do: enum class SomeEnum { foo,…
rekire
  • 47,260
  • 30
  • 167
  • 264
0
votes
2 answers

How to unit test a callback in parameter - Kotlin

I have a Client class (written in Kotlin in an Android app) that implements an interface ReadyCallback (written in Java in a library of the app, the app is dependent on this library). In Client I have a createClient() method which will create a…
peanutnut
  • 1
  • 3
0
votes
1 answer

Cannot instantiate @InjectMocks field named 'viewModel' of type 'class com.example.digiandroidapp.viewmodel.CarViewModel'?

I am developing android app and I have implemented mockito in my viewmodel class in android but when I run the test I am getting following exceptions org.mockito.exceptions.misusing.InjectMocksException: Cannot instantiate @InjectMocks field…
0
votes
1 answer

How does the Mockito-Kotlin mock function work without a class parameter?

Mockito is a mocking framework ( that tastes really good ) mockito-kotlin is a small library that provides helper functions to work with Mockito in Kotlin. Normally from Kotlin to mock an interface with mockito I would write something like val…
Gonen I
  • 5,576
  • 1
  • 29
  • 60
0
votes
1 answer

Failing to use Mockitos thenReturn with predicate - thenReturn returns 404 instead of argument

I'm trying to use Mockito to return some default values in tests but I get a 404 on it My test: @Test fun `Should return 200, when sending a valid push notification`() { // Arrange Mockito.`when`(subscriptionStore.getSubscription{ it.peerID…
0
votes
1 answer

How can I throw an SQLServerException (or SQLException) with Mockito?

I am unable to create an instance of SQLServerException because the ctors are all internal. Getting below error when using SQLException org.mockito.exceptions.base.MockitoException: Checked exception is invalid for this method! Method signature…
Jason
  • 3,844
  • 1
  • 21
  • 40
0
votes
0 answers

Kotlin mockito conflicts between tests

I have a couple of tests failing in my test class when running them all together. When I run them individually, they all work well. So there must be some conflict in the mocked value which I reuse in multiple tests. Here is…
Edster
  • 143
  • 2
  • 13
0
votes
1 answer

How to unit test coruotine with livedata

On the way of learning unit test with mockK I came across with this scenario: MyViewModel: private val _spinner: MutableLiveData = MutableLiveData() val getSpinner : LiveData get() = _spinner fun launchCoruotine() { …
blackHawk
  • 6,047
  • 13
  • 57
  • 100
0
votes
1 answer

Kotlin/Mockito: How to mock "annotationClass" from kotlin.Annotation

I would like to mock annotations to check the good behavior of a class that returns a result according to the given annotation. Here is one of my tests that check the good behavior for with the OneToOne annotation: @Test fun
0
votes
2 answers

How to specify Mockito mock extraInterfaces in Kotlin (using nhaarman mockitokotlin2)

I understand how to specify extraInterface using the @Mock annotation, but how can I create a mock and add the extraInterfaces inline? @SmallTest @RunWith(MockitoJUnitRunner::class) class MyTestClass { @Mock(extraInterfaces =…
VIN
  • 6,385
  • 7
  • 38
  • 77