2

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.

Knot
  • 141
  • 13

1 Answers1

1

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

pvpkiran
  • 25,582
  • 8
  • 87
  • 134