Junit4 : Misplaced or misused argument matcher detected here

20 Views Asked by At

There is one function which is present inside SampleActivity.

@AndroidEntryPoint
class SampleActivity : BaseActivity {
       
        @JvmStatic
        fun isConfigEnabled(string1: String?, string2: String?, string3: String?): Boolean {
            if (!string1.isNullOrEmpty()) {
              // some business logic   
              return true    
            }
            return false
        }
}

I have one Util object(SampleUtil), where by some conditions this function is getting triggered. so I want to mock behaviour of this function, so that whenever it's getting triggered it will give me some result.

@RunWith(JUnit4::class)
class SampleUtil {

    @Test
    fun method() {
        
        val sampleActivityMock = Mockito.mockStatic(SampleActivity::class.java)

        
        sampleActivityMock.`when` {
            SampleActivity.isConfigEnabled(
                anyString(),
                anyString(),
                anyString()
            )
        }.thenReturn(false)

        
        sampleActivityMock.close()
    }
}

Error : Misplaced or misused argument matcher detected here

When I am debugging through function till time of return it's working fine, later this error is coming up.

Thanks in advance.

0

There are 0 best solutions below