Reputation: 141
How can we mock File.createTempFile()
to return our mocked File object?
It should return our mocked file object instead of creating a new temp file and return new object.
Upvotes: 2
Views: 2364
Reputation: 27048
This should do the trick
PowerMockito.mockStatic(File.class);
File mockFile = PowerMockito.mock(File.class);
when(File.createTempFile(anyString(), anyString())).thenReturn(mockFile);
cannot suggest more without the code or test class
Upvotes: 1