I'm trying to test this segment of code using Mockito
if (writeToDisk(filename, byteArray)){ return "URI1" } else { return "URI2" } Since that writeToDisk is intended to be run on a unix server, so using a buffered+fileWriter it writes to "/tmp/upload". The issue is that i'm writing unit tests on a windows machine, and writeToDisk always returns false, because java cannot find "/tmp/upload on windows.
Is there any way I can mock the result of writeToDisk, a pacakge private method?
This is what writeToDisk does:
boolean writeToDisk(String filename, byte[] data){ boolean writeSuccessful = false; try (BufferedWriter writer = new BufferedWriter(new FileWriter("/tmp/upload"+ filename"))){ for (byte current : data){ out.write(current); } writeSuccessful =true; } catch (IOException e) { LOG.debug(e); } return writeSuccessful; }
writeToDiskand test the spy.