I'm trying to cover code that process a file. I'm trying to avoid using real file for tests, so I'm using Mockito. This is the code I'm trying to test:
try {
byte[] data = Files.readAllBytes(((File) body).toPath());
immutableBody = data;
actualHeaderParams.put(HttpHeaders.CONTENT_LENGTH, (new Integer(data.length)).toString());
contentType = MediaType.APPLICATION_OCTET_STREAM;
}
I'm using mock file:
File mockedFile = Mockito.mock(File.class);
but I get an Exception on 'toPath'. So I added some path or null, but then again I get Exceptions since the file doesn't exist in the path.
when(mockedFile.toPath()).thenReturn(Paths.get("test.txt"));
getting:
com.http.ApiException: There was a problem reading the file: test.txt
Is there any way doing it without creating a real file for the test?