v79
07/13/2025, 6:43 PMjava.io.File
object and it's not going well. I've just seen the documentation that says that this class is restricted by default, and cannot be mocked. I definitely used to be able to... seven years ago! What's the best practice for handling these files in mockk now?v79
07/13/2025, 6:51 PMprivate val mockFile: File = mockk()
every { mockFile.name } returns "Simple File (1).md"
With the error message:
java.lang.NullPointerException: Cannot invoke "String.lastIndexOf(int)" because "this.path" is null
at java.base/java.io.File.getName(File.java:456)
at org.liamjd.bascule.model.BasculePostTest$setup$1.invoke(BasculePostTest.kt:49)
Simon Marquis
07/13/2025, 6:54 PMv79
07/13/2025, 6:58 PMval mockFile = File("myfile.md")
is working now. Thank you!
(Definitely did mockk it 7 years ago...)Simon Marquis
07/13/2025, 7:00 PMephemient
07/13/2025, 7:12 PMephemient
07/13/2025, 7:13 PMv79
07/13/2025, 7:14 PMKlitos Kyriacou
07/14/2025, 9:05 AMFile
shouldn't be mocked, can you explain how those two JEPs are relevant to this situation? I don't understand the relevance because the method Liam was trying to mock, File.getName
, is a public method (and File is an open class) but those JEPs are about encapsulating internals.Matteo Mirk
07/14/2025, 12:31 PMv79
07/19/2025, 9:37 AMdata class
- it seems to be final
now? io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
v79
07/19/2025, 9:42 AMKlitos Kyriacou
07/19/2025, 2:04 PMopen
.ephemient
07/19/2025, 4:56 PMephemient
07/19/2025, 4:57 PMKlitos Kyriacou
07/20/2025, 2:46 PM