question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Missing doNothing() method

See original GitHub issue

I think we should be able to do:

whenever(mock.voidMethod()).thenDoNothing()

I know this is the default behavior for void methods, but this can be used to override previously defined then { } block.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

7reactions
nhaarmancommented, Feb 3, 2018

There is a doNothing() function which you place in front of the invocation (like in plain Mockito):

    @Test
    fun testDoNothing() {
        val spy = spy(Open())
        val array = intArrayOf(3)

        doNothing().whenever(spy).modifiesContents(array)
        spy.modifiesContents(array)

        expect(array[0]).toBe(3)
    }

See https://github.com/nhaarman/mockito-kotlin/blob/94f17fa8655a672ef00547dc705f6a49c0a992e9/mockito-kotlin/src/test/kotlin/test/MockitoTest.kt#L290

3reactions
vojtapolcommented, Dec 4, 2020

Concerning doNothing().whenever … , it doesn’t seem to be present in mockitokotlin2. What is the replacement? I couldn’t find anything obvious.

The replacement is https://mockk.io/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Receiving Mockito UnfinishedStubbingException for ...
The doNothing() method from Mockito works a bit different then the standalone when() method. You should be fine by just pushing the method...
Read more >
Missing doNothing() method #225 - mockito/mockito-kotlin
I think we should be able to do: whenever(mock.voidMethod()).thenDoNothing() I know this is the default behavior for void methods, ...
Read more >
org.mockito.Mockito.doNothing java code examples - Tabnine
How to use. doNothing. method. in. org.mockito.Mockito ... @Test public void testFileManagerInit() throws Exception { FilterFileManagerConfig config = new ...
Read more >
Mockito 2.3.4 API - javadoc.io
Mockito verifies argument values in natural java style: by using an equals() method. Sometimes, when extra flexibility is required then you might use...
Read more >
Best of Java : ERROR - org.mockito.exceptions.misusing ...
1. missing thenReturn() 2. you are trying to stub a final method, you naughty developer! 3: you are stubbing the behaviour of another...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found