title: How to mock internally constructed instance with mockk.io?
body: <p>I am writing unit test case in mockk and Junit5 for a static method defined in companion object of FileUtility class.</p>
  
  <p>the method is as below,</p>
  
  <pre><code>class FileUtility {
  
      companion object {
          fun getFileObject(fileName: String): File {
              require(!StringUtils.isBlank(fileName)) { "Expecting a valid filePath" }
              val file = File(fileName)
              if (file.isHidden)
                  throw llegalArgumentException()
              return file
          }
      }
  
  }
  </code></pre>
  
  <p>the unit test case is as below,</p>
  
  <pre><code>@Test
  fun `get file object test throws exception when file path is hidden`() {
      val filePath = "filepath"
      val file = mockk&lt;File&gt;()
      every { file.isHidden } returns true
      assertThrows(IllegalArgumentException::class.java) {
          getFileObject(filePath)
      }
      verify { file.isHidden}
  }
  </code></pre>
  
  <p>getting the following error,</p>
  
  <pre><code>Expected java.lang.Exception to be thrown, but nothing was thrown.
  </code></pre>
  
  <p>Also, the <code>verify { file.isHidden}</code> line is not working, its giving the following error.</p>
  
  <pre><code>java.lang.AssertionError: Verification failed: call 1 of 1: File(#1).isHidden()) was not called
  </code></pre>