0

I am trying to unit test some code that looks like this

fun doSomething() {
    val someObject: SomeObject?
    if (someObject != null) {
        val file: File = File(someObject.path)
        if (file.exists()) {
            // Do some stuff 1.1
        } else {
            // Do some stuff 1.2
        }
    } else {
        // Some some stuff 2
    }
}

I want to test for the time where someObject is not null, and file.exists == true. I am trying to mock this with mockito, because I do not need the file to actually exist during my test. The logic around it is more important to me. Is it possible to do something like this?

whenever(type(File::class.java).exists()).thenReturn(true)

so that any file during the test will always resolve to true when checking if it exists or not?

Lesiak
  • 17,075
  • 2
  • 28
  • 53

0 Answers0