mockito return value based on property of a parameter

前端 未结 5 1637
没有蜡笔的小新
没有蜡笔的小新 2021-01-30 19:57

Normally when using mockito I will do something like

Mockito.when(myObject.myFunction(myParameter)).thenReturn(myResult);

Is it possible to do

5条回答
  •  臣服心动
    2021-01-30 20:27

    Here is how it would look like in Kotlin with mockito-kotlin library.

    mock {
        on {
            mockObject.myMethod(any())
        } doAnswer {
            "Here is the value: ${it.arguments[0]}"
        }
    }
    

提交回复
热议问题