I want to stub the public static function readAllBytes from java.nio.file.Files with the following test code.
@PrepareForTest(Files.class)
public void testGetNotExistingRestFile() throws Exception {
PowerMockito.mockStatic(Files.class);
PowerMockito.doThrow(mock(IOException.class)).when(Files.readAllBytes(any(Path.class)));
}
Every time an NullPointerException is thrown and I can figure out what I'm doing wrong.
java.lang.NullPointerException
at java.nio.file.Files.provider(Files.java:67)
at java.nio.file.Files.newByteChannel(Files.java:317)
at java.nio.file.Files.newByteChannel(Files.java:363)
at java.nio.file.Files.readAllBytes(Files.java:2981)
at nl.mooij.bob.RestFileProviderTest.testGetNotExistingRestFile(RestFileProviderTest.java:53)
How can I stub the function readAllBytes from java.nio.file.Files with PowerMockito?